gpt4 book ai didi

java - 通过Java客户端连接Azure服务总线

转载 作者:行者123 更新时间:2023-11-30 08:20:15 24 4
gpt4 key购买 nike

我正在尝试使用 AMQP 协议(protocol)从 Java 客户端连接 Azure 服务总线

我按照以下链接中的说明进行操作:
http://azure.microsoft.com/en-us/documentation/articles/service-bus-java-how-to-use-jms-api-amqp/

1) 在 Azure 门户中使用 namespace “availo”和名为“queue1”的队列创建服务总线
2)从服务总线连接信息中我得到以下信息:

SharedAccessKeyName=RootManageSharedAccessKey
SharedAccessKey={key}

3) 创建用于 JNDI 查找的“servicebus.properties”文件

   connectionfactory.SBCF = amqps://RootManageSharedAccessKey:encoded(key)@availo.servicebus.windows.net
queue.QUEUE = queue1

4) 下面是我的简单 java 主应用程序,类路径中包含所有必需的 jar (qpid)。

  public static void main(String[] args) {

try {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
env.put(Context.PROVIDER_URL,
"C:\\Users\\Assaf-PC\\Documents\\GitHub\\availo\\rest-api\\src\\main\\resources\\servicebus.properties");
Context context = new InitialContext(env);
// Lookup ConnectionFactory and Queue
ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF");
Destination queue = (Destination) context.lookup("QUEUE");
// Create Connection
Connection connection = cf.createConnection();
// Create sender-side Session and MessageProducer
Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = sendSession.createProducer(queue);
} catch (Exception e) {
e.getLocalizedMessage();
}

}

当我运行该程序时,我在代码行中收到以下异常:

    MessageProducer producer = sendSession.createProducer(queue);

异常(exception):

Exception in thread "main" javax.jms.JMSException: Peer did not create remote endpoint for link, target: queue1
at org.apache.qpid.amqp_1_0.jms.impl.MessageProducerImpl.<init>(MessageProducerImpl.java:98)
at org.apache.qpid.amqp_1_0.jms.impl.SessionImpl.createProducer(SessionImpl.java:390)
at org.apache.qpid.amqp_1_0.jms.impl.SessionImpl.createProducer(SessionImpl.java:59)
at availo.rest.services.ServiceBus.main(ServiceBus.java:43)
Caused by: org.apache.qpid.amqp_1_0.client.Sender$SenderCreationException: Peer did not create remote endpoint for link, target: queue1
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:191)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:119)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:112)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:98)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:84)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:78)
at org.apache.qpid.amqp_1_0.client.Session$1.<init>(Session.java:90)
at org.apache.qpid.amqp_1_0.client.Session.createSender(Session.java:89)
at org.apache.qpid.amqp_1_0.jms.impl.MessageProducerImpl.<init>(MessageProducerImpl.java:86)
... 3 more

浪费了很多时间来了解我做错了什么但没有成功,有人可以帮忙吗?
非常感谢您的回答。

最佳答案

确保您的队列未启用分区。 ServiceBus 不支持带有分区队列的 AMQP,但是默认情况下会在创建队列时启用分区。

我遇到了完全相同的错误,并且在未选中“启用分区”的情况下重新创建队列为我解决了这个问题。

请参阅本文底部的分区实体限制部分:https://msdn.microsoft.com/en-us/library/azure/dn520246.aspx

Partitioned queues and topics are only available via SBMP or HTTP/HTTPS. AMQP support will be added in the future.

关于java - 通过Java客户端连接Azure服务总线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26200849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com