Home > Enterprise >  ServiceBusAdminClient listRules does not return all of the rules for a subscription
ServiceBusAdminClient listRules does not return all of the rules for a subscription

Time:06-08

I've using the Java API Library (version 7.5.2) to manage queues and topics in Service Bus Namespace. And I am seeing an error.

I have code which checks subcriptions for topics to ensure they are uptodate. If they are not, then the code updates them.

The first step is, for a Topic and Subscription I use listRules.

PagedIterable<RuleProperties> rulesIter = serviceBusAdminClient.listRules(topicDef.getName(), subscriptionDef.getName());

The issue I am seeing is that it only returns one rule. I have a Subscription that has two Filters in it in the portal. Yet listRules only ever returns one. Then it all falls over because my code attempts to create the "missing" rule only to have an exception thrown because the rule already exists.

Originally, I was using stream() to get the names of all the rules...

listRulesResult.stream().map(RuleProperties::getName).collect(Collectors.toList());

And it always returned one record.

I've been trying to use streamByPage and iterateByPage but that has made no difference. When the code lists Queues and Topics, multiple records are returned. But not for Rules for a Subscription (which should be able to support multiple rules).

-update- when I attempt to fetch the existing Rule (one that is not returned via listRules) using getRule, it is returned.

-another update- I created a test harness to provide to the issue I was going to raise. And it worked as I had hoped. There must be something in the classpath which is affecting this. Hope to have an update about what the root cause is soon. But, for now, this does work in a cut-down test harness (instead of my app).

CodePudding user response:

According to documentation, you can fetch all the rules for a topic and subscription using PagedIterable:

public PagedIterable<RuleProperties> listRules(String topicName, String subscriptionName) {
        return new PagedIterable<>(asyncClient.listRules(topicName, subscriptionName));
    }

You can refer to ServiceBusAdministrationClient class listrules(), ServiceBusAdministrationClient.javaand ServiceBusAdministrationClient

CodePudding user response:

This looks to have been caused by Jackson dependencies that were being brought in by Spring Boot.

When this was failing, I was using version 2.11.4 of Jackson, as defined by default by Spring Boot.

I noticed that, when just using Azure's BOM, it was using version 2.13.2 of Jackson.

So I updated my application to override Spring Boot's declaration and, instead, use Jackson version 2.13.2. With these dependencies in the classpath, all of the rules for the subscription were returned as I would have expected.

  • Related