无法使用 java 连接到 azure 服务总线主题
Cant connect to azure service bus topic using java
我正在尝试使用 java 代码连接到 Azure 服务总线主题。
我在 azure portal 中创建了一个主题。
我正在尝试使用 configureWithWrapAuthentication 方法进行配置,该方法具有参数 namespace,authenticationName,authenticationPassword,serviceBusRootUri,wrapRootUri 。
我获取了除 wrapRootUri 之外的所有参数值。
仅供参考:我选择的区域是 South India
我需要知道南印度位置的 wrapRootUri 的值是多少。
请帮忙!
提前致谢。
服务总线团队关于从 ACS 到 SAS 的更改。似乎它不再起作用了。根据 github 有一个 open issue。
如果你想连接或管理 Azure 服务总线。我建议您可以使用以下 SDK.
<!-- 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>
更新: 添加包信息。
演示代码
import com.microsoft.azure.servicebus.ClientSettings;
import com.microsoft.azure.servicebus.Message;
import com.microsoft.azure.servicebus.TopicClient;
import com.microsoft.azure.servicebus.management.ManagementClient;
import com.microsoft.azure.servicebus.management.TopicDescription;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import com.microsoft.azure.servicebus.security.SharedAccessSignatureTokenProvider;
import com.microsoft.azure.servicebus.security.TokenProvider;
String connectionString = "Endpoint=sb://yoursevicebusNamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=xxxxx";
ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(connectionString);
ManagementClient client = new ManagementClient(connectionStringBuilder);
//create topic
if(!client.queueExists("topicName"))
{
TopicDescription topic = client.createTopic("topicName");
}
TokenProvider tokenProvider = new SharedAccessSignatureTokenProvider("RootManageSharedAccessKey","xxxxxx",30);
ClientSettings clientSettings = new ClientSettings(tokenProvider){};
//create topicClient
TopicClient topicClient = new TopicClient(connectionStringBuilder.getEndpoint(),"topicName",clientSettings);
//send message
topicClient.send(new Message("test message"));
我正在尝试使用 java 代码连接到 Azure 服务总线主题。 我在 azure portal 中创建了一个主题。
我正在尝试使用 configureWithWrapAuthentication 方法进行配置,该方法具有参数 namespace,authenticationName,authenticationPassword,serviceBusRootUri,wrapRootUri 。
我获取了除 wrapRootUri 之外的所有参数值。 仅供参考:我选择的区域是 South India
我需要知道南印度位置的 wrapRootUri 的值是多少。
请帮忙! 提前致谢。
服务总线团队关于从 ACS 到 SAS 的更改。似乎它不再起作用了。根据 github 有一个 open issue。
如果你想连接或管理 Azure 服务总线。我建议您可以使用以下 SDK.
<!-- 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>
更新: 添加包信息。
演示代码
import com.microsoft.azure.servicebus.ClientSettings;
import com.microsoft.azure.servicebus.Message;
import com.microsoft.azure.servicebus.TopicClient;
import com.microsoft.azure.servicebus.management.ManagementClient;
import com.microsoft.azure.servicebus.management.TopicDescription;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import com.microsoft.azure.servicebus.security.SharedAccessSignatureTokenProvider;
import com.microsoft.azure.servicebus.security.TokenProvider;
String connectionString = "Endpoint=sb://yoursevicebusNamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=xxxxx";
ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(connectionString);
ManagementClient client = new ManagementClient(connectionStringBuilder);
//create topic
if(!client.queueExists("topicName"))
{
TopicDescription topic = client.createTopic("topicName");
}
TokenProvider tokenProvider = new SharedAccessSignatureTokenProvider("RootManageSharedAccessKey","xxxxxx",30);
ClientSettings clientSettings = new ClientSettings(tokenProvider){};
//create topicClient
TopicClient topicClient = new TopicClient(connectionStringBuilder.getEndpoint(),"topicName",clientSettings);
//send message
topicClient.send(new Message("test message"));