如何使用 Java 在 Azure 服务总线中创建队列?

How to create a Queue in Azure Service Bus using Java?

我需要从代码中提供服务总线队列,但我似乎无法找到有关如何执行此操作的任何详细信息。 Azure 服务总线库有一个正在创建队列的单元测试 (link),但我引用的 Maven 库没有任何 类(QueueDescription 或 ManagementClientAsync)。

有没有人试过从 java 动态创建队列?

行家:

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

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.

您提到的 QueueDescriptionManagementClientAsync 似乎仅在 2.0.0-PREVIEW version 中可用。请尝试使用以下依赖项。

<!-- 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>

演示代码:

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");
}