1
votes

I need to provision a Service Bus queue from code but I can't seem to find any details on how to do it. The Azure Service bus library has a unit test that is creating the queue (link) but the maven library I've referenced doesn't have any of those classes (QueueDescription or ManagementClientAsync).

Has anyone tried creating a queue dynamically from java?

Maven:

<dependency> 
  <groupId>com.microsoft.azure</groupId> 
  <artifactId>azure-servicebus</artifactId> 
  <version>1.2.5</version>
</dependency>
1

1 Answers

3
votes

I've referenced doesn't have any of those classes (QueueDescription or ManagementClientAsync).

However this class seem not to be part of azure-core or azure-servicebus librairy and I can seem to find which lib to add to the project to have access to those class.

You mentioned QueueDescription or ManagementClientAsync seems only available in the 2.0.0-PREVIEW version. Please have a try to use the following dependency.

<!-- https://mvnrepository.com/artifact/com.microsoft.azure/azure-servicebus -->
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-servicebus</artifactId>
    <version>2.0.0-PREVIEW-5</version>
</dependency>

Demo code:

String connectionString = "Endpoint=sb://xxxx.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=xxxxxx";
ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(connectionString);
ManagementClient client = new ManagementClient(connectionStringBuilder);
if(!client.queueExists("queueName"))
{
    QueueDescription queue = client.createQueue("queueName");
}