【问题标题】:Cant connect to azure service bus topic using java无法使用 java 连接到 Azure 服务总线主题
【发布时间】:2019-03-05 14:45:22
【问题描述】:

我正在尝试使用 java 代码连接到 Azure 服务总线主题。 我在 azure 门户中创建了一个主题。

我正在尝试使用 configureWithWrapAuthentication 方法进行配置,该方法具有参数 namespace,authenticationName,authenticationPassword,serviceBusRootUri,wrapRootUri

我获得了除 wrapRootUri 之外的所有参数值。 仅供参考:我选择的地区是 South India

我需要知道 wrapRootUri 对于南印度位置的价值。

请帮忙! 提前致谢。

【问题讨论】:

    标签: java azure azureservicebus


    【解决方案1】:

    服务总线团队正在从 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"));
    

    【讨论】:

    • 你能把 ManagementClient 和 TopicDescription 的导入发给我吗
    • @MithunManohar 我已经通过导入包信息更新了答案。
    • 能否请您也添加代码以接收消息
    • @MithunManohar 如果您有任何其他问题,我建议您可以发布另一个 SO 线程。如果有用,您可以将其标记为答案。
    • TokenProvider tokenProvider = new SharedAccessSignatureTokenProvider("RootManageSharedAccessKey","xxxx",30); ClientSettings clientSettings = new ClientSettings(tokenProvider){}; IMessageReceiver receiver = ClientFactory.createMessageReceiverFromEntityPath("servicebusNamespace","topicName",clientSettings); receiver.receive();
    猜你喜欢
    • 2018-05-29
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多