1

我正在编写我的第一个应用程序来从 EventHub 发送和接收。我正在遵循Azure doc中提供的示例。

我的 servicebus.properties 文件看起来像这样。

connectionfactory.SBCF = amqps://SendRule:BLAH..blah@mynamespace.servicebus.windows.net/?sync-publish=false
queue.EventHub = eventhub1

我的发件人代码如下所示

    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, "servicebus.properties");
    Context context = new InitialContext(env);

    ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF");
    Destination queue = (Destination) context.lookup("EventHub");
    Connection connection = cf.createConnection();
    Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer sender = sendSession.createProducer(queue);

我遇到了一个例外

Exception in thread "main" javax.jms.JMSException: Peer did not create remote endpoint for link, target: eventhub1
    at org.apache.qpid.amqp_1_0.jms.impl.MessageProducerImpl.<init>(MessageProducerImpl.java:69)
    at org.apache.qpid.amqp_1_0.jms.impl.SessionImpl.createProducer(SessionImpl.java:293)
    at org.apache.qpid.amqp_1_0.jms.impl.SessionImpl.createProducer(SessionImpl.java:57)
    at com.commvault.azure.Sender.main(Sender.java:39)

当我搜索解决方案时,我得到了关于 ServiceBus 队列的帮助,并且使用的连接字符串格式为 [用户名]:[密码]:[命名空间]。在 EventHub 上找不到任何帮助。

有什么建议缺少什么吗?

4

0 回答 0