无法从.Net应用程序发送的Qpid JMS(qpid-jms-client-0.11.1.jar)中的Azure Service Bus接收消息

时间:2016-11-03 14:17:10

标签: java jms amqp azureservicebus qpid

我创建了2个Java Demo应用程序,它们使用以下指南连接到已配置的Azure Service Bus:

  • 如何将Java消息服务(JMS)API与Service Bus和AMQP 1.0一起使用 - azure.microsoft.com/nl-nl/documentation/articles/service-bus-java-how-to-use-jms-api -amqp
  • Qpid JMS 0.11.1文档 - qpid.apache.org/releases/qpid-jms-0.11.1/docs/index.html

Sender.java应用程序可以在预配置的Azure Service Bus上成功将消息放入队列中。 SimpleReceiver.java应用程序设置为从Azure ServiceBus上的队列接收消息。

目前,SimpleReceiver.java可以成功接收最初从Sender.java应用程序发送到Service Bus的消息。但是没有收到由.Net(C#)Sender.cs app发送的消息。

如何实现/设置SimpleReceiver.java以接收来自Azure Service Bus Queue的所有消息? (使用Qpid JMS 0.11.1)

旁注:我可以使用旧库Qpid JMS 0.32来实现这一点。但版本0.11.1是必需的。

总结一下到目前为止:

  • [works] Sender.java - > Azure Service Bus - > SimpleReceiver.java
  • [works] Sender.java - > Azure Service Bus - > (.Net)Receiver.cs
  • [works](。Net)Sender.cs - > Azure Service Bus - > (.Net)Receiver.cs
  • [失败](。Net)Sender.cs - > Azure Service Bus - > SimpleReceiver.java

当我尝试使用SimpleReceiver.java接收.Net发送的消息时,我得到以下跟踪/日志:

2016-11-07 09:44:18,778 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - SSL Handshake has completed: [id: 0xe1a2112b, L:/10.70.1.160:57828 - R:demo-sandbox-open-bus.servicebus.windows.net/13.69.253.135:5671]
2016-11-07 09:44:18,778 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - Channel has become active! Channel is [id: 0xe1a2112b, L:/10.70.1.160:57828 - R:demo-sandbox-open-bus.servicebus.windows.net/13.69.253.135:5671]
2016-11-07 09:44:18,778 [ntLoopGroup-2-1] - DEBUG SslHandler                     - [id: 0xe1a2112b, L:/10.70.1.160:57828 - R:demo-sandbox-open-bus.servicebus.windows.net/13.69.253.135:5671] HANDSHAKEN: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
connection :org.apache.qpid.jms.JmsConnection@c1c084f
2016-11-07 09:44:18,813 [us.windows.net]] - TRACE MetaDataSupport                - Problem generating primary version details
java.lang.NullPointerException
    at java.util.regex.Matcher.getTextLength(Matcher.java:1234)
    at java.util.regex.Matcher.reset(Matcher.java:308)
    at java.util.regex.Matcher.<init>(Matcher.java:228)
    at java.util.regex.Pattern.matcher(Pattern.java:1088)
    at org.apache.qpid.jms.util.MetaDataSupport.<clinit>(MetaDataSupport.java:47)
    at org.apache.qpid.jms.provider.amqp.builders.AmqpConnectionBuilder.createEndpoint(AmqpConnectionBuilder.java:108)
    at org.apache.qpid.jms.provider.amqp.builders.AmqpConnectionBuilder.createEndpoint(AmqpConnectionBuilder.java:41)
    at org.apache.qpid.jms.provider.amqp.builders.AmqpResourceBuilder.buildResource(AmqpResourceBuilder.java:72)
    at org.apache.qpid.jms.provider.amqp.builders.AmqpConnectionBuilder.buildResource(AmqpConnectionBuilder.java:94)
    at org.apache.qpid.jms.provider.amqp.AmqpProvider$4$1.processConnectionInfo(AmqpProvider.java:323)
    at org.apache.qpid.jms.meta.JmsConnectionInfo.visit(JmsConnectionInfo.java:373)
    at org.apache.qpid.jms.provider.amqp.AmqpProvider$4.run(AmqpProvider.java:252)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
2016-11-07 09:44:18,819 [us.windows.net]] - TRACE NettyTcpTransport              - Attempted write of: 8 bytes
2016-11-07 09:44:18,845 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - New data read: 8 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 8, cap: 37)
2016-11-07 09:44:18,846 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: CONNECTION_INIT
2016-11-07 09:44:18,847 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: CONNECTION_LOCAL_OPEN
2016-11-07 09:44:18,926 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - New data read: 63 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 63, cap: 101)
2016-11-07 09:44:18,928 [us.windows.net]] - DEBUG SaslMechanismFinder            - Unknown SASL mechanism: [MSSBCBS]
2016-11-07 09:44:18,931 [us.windows.net]] - DEBUG SaslMechanismFinder            - Skipping SASL-EXTERNAL mechanism because the available credentials are not sufficient
2016-11-07 09:44:18,931 [us.windows.net]] - INFO  SaslMechanismFinder            - Best match for SASL auth was: SASL-PLAIN
2016-11-07 09:44:18,933 [us.windows.net]] - TRACE NettyTcpTransport              - Attempted write of: 125 bytes
2016-11-07 09:44:18,958 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - New data read: 26 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 26, cap: 53)
[395414939:0] -> Open{ containerId='ID:9669bcc7-59c0-43eb-9908-00605f8153dd:1', hostname='demo-sandbox-open-bus.servicebus.windows.net', maxFrameSize=1048576, channelMax=32767, idleTimeOut=75000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null, desiredCapabilities=[sole-connection-for-container], properties={product=QpidJMS, version=0.11.1, platform=JVM: 1.7.0_75, 24.75-b04, Oracle Corporation, OS: Windows 8.1, 6.3, amd64}}
2016-11-07 09:44:18,961 [us.windows.net]] - TRACE FRAMES                         - SENT: Open{ containerId='ID:9669bcc7-59c0-43eb-9908-00605f8153dd:1', hostname='demo-sandbox-open-bus.servicebus.windows.net', maxFrameSize=1048576, channelMax=32767, idleTimeOut=75000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null, desiredCapabilities=[sole-connection-for-container], properties={product=QpidJMS, version=0.11.1, platform=JVM: 1.7.0_75, 24.75-b04, Oracle Corporation, OS: Windows 8.1, 6.3, amd64}}
2016-11-07 09:44:18,961 [us.windows.net]] - TRACE NettyTcpTransport              - Attempted write of: 290 bytes
2016-11-07 09:44:18,985 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - New data read: 8 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 8, cap: 37)
2016-11-07 09:44:19,061 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - New data read: 70 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 70, cap: 101)
[395414939:0] <- Open{ containerId='d3a14a268d4c45b1a5f6acabc01c1bdd_G43', hostname='null', maxFrameSize=65536, channelMax=4999, idleTimeOut=240000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,061 [us.windows.net]] - TRACE FRAMES                         - RECV: Open{ containerId='d3a14a268d4c45b1a5f6acabc01c1bdd_G43', hostname='null', maxFrameSize=65536, channelMax=4999, idleTimeOut=240000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,061 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: CONNECTION_REMOTE_OPEN
2016-11-07 09:44:19,064 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: SESSION_INIT
2016-11-07 09:44:19,064 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: SESSION_LOCAL_OPEN
[395414939:0] -> Begin{remoteChannel=null, nextOutgoingId=1, incomingWindow=2047, outgoingWindow=2147483647, handleMax=65535, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,066 [us.windows.net]] - TRACE FRAMES                         - SENT: Begin{remoteChannel=null, nextOutgoingId=1, incomingWindow=2047, outgoingWindow=2147483647, handleMax=65535, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,066 [us.windows.net]] - TRACE NettyTcpTransport              - Attempted write of: 32 bytes
2016-11-07 09:44:19,091 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - New data read: 34 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 34, cap: 69)
[395414939:0] <- Begin{remoteChannel=0, nextOutgoingId=1, incomingWindow=5000, outgoingWindow=2047, handleMax=255, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,091 [us.windows.net]] - TRACE FRAMES                         - RECV: Begin{remoteChannel=0, nextOutgoingId=1, incomingWindow=5000, outgoingWindow=2047, handleMax=255, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,091 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: SESSION_REMOTE_OPEN
2016-11-07 09:44:19,091 [us.windows.net]] - DEBUG AmqpConnectionBuilder          - AmqpConnection { ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1 } is now open: 
2016-11-07 09:44:19,091 [us.windows.net]] - TRACE AmqpProvider                   - IdleTimeoutCheck being initiated, initial delay: 120000
2016-11-07 09:44:19,092 [us.windows.net]] - INFO  JmsConnection                  - Connection ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1 connected to remote Broker: amqps://demo-sandbox-open-bus.servicebus.windows.net
[395414939:1] -> Begin{remoteChannel=null, nextOutgoingId=1, incomingWindow=2047, outgoingWindow=2147483647, handleMax=65535, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,102 [us.windows.net]] - TRACE FRAMES                         - SENT: Begin{remoteChannel=null, nextOutgoingId=1, incomingWindow=2047, outgoingWindow=2147483647, handleMax=65535, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,102 [us.windows.net]] - TRACE NettyTcpTransport              - Attempted write of: 32 bytes
2016-11-07 09:44:19,126 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - New data read: 34 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 34, cap: 69)
[395414939:1] <- Begin{remoteChannel=1, nextOutgoingId=1, incomingWindow=5000, outgoingWindow=2047, handleMax=255, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,126 [us.windows.net]] - TRACE FRAMES                         - RECV: Begin{remoteChannel=1, nextOutgoingId=1, incomingWindow=5000, outgoingWindow=2047, handleMax=255, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,126 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: SESSION_INIT
2016-11-07 09:44:19,126 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: SESSION_LOCAL_OPEN
2016-11-07 09:44:19,126 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: SESSION_REMOTE_OPEN
[395414939:1] -> Attach{name='qpid-jms:receiver:ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1:a_receiver/verwerker/klant', handle=0, role=RECEIVER, sndSettleMode=UNSETTLED, rcvSettleMode=FIRST, source=Source{address='a_receiver/verwerker/klant', durable=NONE, expiryPolicy=LINK_DETACH, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=Modified{deliveryFailed=true, undeliverableHere=null, messageAnnotations=null}, outcomes=[amqp:accepted:list, amqp:rejected:list, amqp:released:list, amqp:modified:list], capabilities=[queue]}, target=Target{address='null', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, capabilities=null}, unsettled=null, incompleteUnsettled=false, initialDeliveryCount=null, maxMessageSize=null, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,138 [us.windows.net]] - TRACE FRAMES                         - SENT: Attach{name='qpid-jms:receiver:ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1:a_receiver/verwerker/klant', handle=0, role=RECEIVER, sndSettleMode=UNSETTLED, rcvSettleMode=FIRST, source=Source{address='a_receiver/verwerker/klant', durable=NONE, expiryPolicy=LINK_DETACH, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=Modified{deliveryFailed=true, undeliverableHere=null, messageAnnotations=null}, outcomes=[amqp:accepted:list, amqp:rejected:list, amqp:released:list, amqp:modified:list], capabilities=[queue]}, target=Target{address='null', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, capabilities=null}, unsettled=null, incompleteUnsettled=false, initialDeliveryCount=null, maxMessageSize=null, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,138 [us.windows.net]] - TRACE NettyTcpTransport              - Attempted write of: 276 bytes
2016-11-07 09:44:19,164 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - New data read: 310 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 310, cap: 341)
[395414939:1] <- Attach{name='qpid-jms:receiver:ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1:a_receiver/verwerker/klant', handle=0, role=SENDER, sndSettleMode=MIXED, rcvSettleMode=SECOND, source=Source{address='a_receiver/verwerker/klant', durable=NONE, expiryPolicy=LINK_DETACH, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=Modified{deliveryFailed=true, undeliverableHere=null, messageAnnotations=null}, outcomes=[amqp:accepted:list, amqp:rejected:list, amqp:released:list, amqp:modified:list], capabilities=[queue]}, target=Target{address='null', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, capabilities=null}, unsettled=null, incompleteUnsettled=false, initialDeliveryCount=0, maxMessageSize=266240, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,164 [us.windows.net]] - TRACE FRAMES                         - RECV: Attach{name='qpid-jms:receiver:ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1:a_receiver/verwerker/klant', handle=0, role=SENDER, sndSettleMode=MIXED, rcvSettleMode=SECOND, source=Source{address='a_receiver/verwerker/klant', durable=NONE, expiryPolicy=LINK_DETACH, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=Modified{deliveryFailed=true, undeliverableHere=null, messageAnnotations=null}, outcomes=[amqp:accepted:list, amqp:rejected:list, amqp:released:list, amqp:modified:list], capabilities=[queue]}, target=Target{address='null', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, capabilities=null}, unsettled=null, incompleteUnsettled=false, initialDeliveryCount=0, maxMessageSize=266240, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,165 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: LINK_INIT
2016-11-07 09:44:19,165 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: LINK_LOCAL_OPEN
2016-11-07 09:44:19,165 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: LINK_REMOTE_OPEN
2016-11-07 09:44:19,166 [us.windows.net]] - TRACE AmqpConsumer                   - Consumer ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1 granting additional credit: 1000
receiver.getMessageSelector(): is null
[395414939:1] -> Flow{nextIncomingId=1, incomingWindow=2047, nextOutgoingId=1, outgoingWindow=2147483647, handle=0, deliveryCount=0, linkCredit=1000, available=null, drain=false, echo=false, properties=null}
2016-11-07 09:44:19,167 [us.windows.net]] - TRACE FRAMES                         - SENT: Flow{nextIncomingId=1, incomingWindow=2047, nextOutgoingId=1, outgoingWindow=2147483647, handle=0, deliveryCount=0, linkCredit=1000, available=null, drain=false, echo=false, properties=null}
2016-11-07 09:44:19,167 [us.windows.net]] - TRACE NettyTcpTransport              - Attempted write of: 35 bytes
Type 'exit' + [enter] to quit.
2016-11-07 09:44:19,194 [ntLoopGroup-2-1] - TRACE NettyTcpTransport              - New data read: 548 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 548, cap: 581)
[395414939:1] <- Transfer{handle=0, deliveryId=0, deliveryTag=~\x00\x5c#\xa0j\xd6A\x92N\x82\x91\x1a\x09\xd3\x12, messageFormat=0, settled=null, more=false, rcvSettleMode=null, state=null, resume=false, aborted=false, batchable=true} (506) "\x00Sp\xc0\x0a\x05@@p\x0er\xbb\x00@C\x00Sr\xc1\x5c\x06\xa3\x13x-opt-enqueued-time\x83\x00\x00\x01X=\xf5\x108\xa3\x15x-opt-sequence-number\x81\x00\x00\x00\x00\x00\x00\x01\xca\xa3\x12x-opt-locked-until\x83\x00\x00\x01X=\xf6\x96\xcf\x00Ss\xc0=\x0d\xa1\x1dtestsender2016-11-07T09:43:38@@@@@\xa3\x10application/json@@@@@@\x00St\xc1\xb5\x0e\xa1\x0bMessageType\xa1\x0fDocumentMessage\xa1\x0cSourceSystem\xa1\x0asis_sender\xa1\x0dEnterpriseKey\xa1\x18sis_sender-klant-bericht\xa1\x08TenantId\xa1\x05klant\xa1\x09EventType\xa1\x07bericht\xa1\x10EventTypeVersion\xa1\x031.0\xa1\x0dOperationType\xa1\x06Create\x00Su\xa0\x89@\x06string\x083http://schemas.microsoft.com/2003/10/Serialization/\x99J{"id": 1,"name": "A .net door","price": 12.50,"tags": ["home", "C# .Net"]}"
2016-11-07 09:44:19,201 [us.windows.net]] - TRACE FRAMES                         - RECV: Transfer{handle=0, deliveryId=0, deliveryTag=~\x00\x5c#\xa0j\xd6A\x92N\x82\x91\x1a\x09\xd3\x12, messageFormat=0, settled=null, more=false, rcvSettleMode=null, state=null, resume=false, aborted=false, batchable=true}
2016-11-07 09:44:19,203 [us.windows.net]] - TRACE AmqpProvider                   - New Proton Event: DELIVERY
2016-11-07 09:44:19,203 [us.windows.net]] - TRACE AmqpConsumer                   - AmqpConsumer { ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1 } has incoming Message(s).
2016-11-07 09:44:19,210 [us.windows.net]] - DEBUG AmqpConsumer                   - Dispatching received message: JmsInboundMessageDispatch {sequence = 1, messageId = testsender2016-11-07T09:43:38, consumerId = ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1}
2016-11-07 09:44:19,211 [1:1] dispatcher] - TRACE JmsMessageConsumer             - checking envelope with 0 redeliveries
2016-11-07 09:44:19,212 [us.windows.net]] - DEBUG AmqpConsumer                   - Delivered Ack of message: JmsInboundMessageDispatch {sequence = 1, messageId = testsender2016-11-07T09:43:38, consumerId = ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1}

我还有一个comparison of a message sent by Java vs one sent by .net(C#)(从Service Bus Explorer导出的消息)。我觉得它与发送的内容类型/消息类型有关。

下面是Java发送的成功消息的跟踪/日志以及.Net发送的Unsucceful消息:

[2138532527:1] <- Transfer{handle=0, deliveryId=0, deliveryTag=Z\x80\x91\x15\xa3v{D\x96`\x04\x1ad\xb8;V, messageFormat=0, settled=null, more=false, rcvSettleMode=null, state=null, resume=false, aborted=false, batchable=true} (529) "\x00Sp\xc0\x0a\x05B@p\x0er\xbb\x00@C\x00Sr\xc1\x84\x0a\xa3\x12x-opt-jms-msg-typeQ\x05\xa3\x0ex-opt-jms-destQ\x00\xa3\x13x-opt-enqueued-time\x83\x00\x00\x01X*i\x17!\xa3\x15x-opt-sequence-number\x81\x00\x00\x00\x00\x00\x00\x01\xa9\xa3\x12x-opt-locked-until\x83\x00\x00\x01X*j\x01\x91\x00Ss\xc0t\x0d\xa1/ID:e076122e-f27d-4cdd-9b13-33e75716d70a:1:1:1-1@\xa1\x1csis_receiver/verwerker/klant\xa1\x10application/json@@@@@\x83\x00\x00\x01X*i\x12h@@@\x00St\xc1\xb5\x0e\xa1\x08TenantId\xa1\x05klant\xa1\x0dEnterpriseKey\xa1\x18sis_sender-klant-bericht\xa1\x09EventType\xa1\x07bericht\xa1\x10EventTypeVersion\xa1\x031.0\xa1\x0bMessageType\xa1\x0fDocumentMessage\xa1\x0dOperationType\xa1\x06Create\xa1\x0cSourceSystem\xa1\x0asis_sender\x00Sw\xa1A{"logged":false,"userID":"0","bericht Marvin Java":"test body2"} "
Received message with JMSMessageID = ID:e076122e-f27d-4cdd-9b13-33e75716d70a:1:1:1-1
[2138532527:1] -> Disposition{role=RECEIVER, first=0, last=0, settled=true, state=Accepted{}, batchable=false}
[2138532527:1] <- Transfer{handle=0, deliveryId=1, deliveryTag=\xd7\xbb\x1b\xcb>\x91\x14O\xa2\x83q\x9e\xc9|N\x09, messageFormat=0, settled=null, more=false, rcvSettleMode=null, state=null, resume=false, aborted=false, batchable=true} (504) "\x00Sp\xc0\x0a\x05@@p\x0er\xbb\x00@C\x00Sr\xc1\x5c\x06\xa3\x13x-opt-enqueued-time\x83\x00\x00\x01X*i\x5c\x10\xa3\x15x-opt-sequence-number\x81\x00\x00\x00\x00\x00\x00\x01\xaa\xa3\x12x-opt-locked-until\x83\x00\x00\x01X*jFp\x00Ss\xc0=\x0d\xa1\x1dtestsender2016-11-03T14:38:15@@@@@\xa3\x10application/json@@@@@@\x00St\xc1\xb5\x0e\xa1\x0bMessageType\xa1\x0fDocumentMessage\xa1\x0cSourceSystem\xa1\x0asis_sender\xa1\x0dEnterpriseKey\xa1\x18sis_sender-klant-bericht\xa1\x08TenantId\xa1\x05klant\xa1\x09EventType\xa1\x07bericht\xa1\x10EventTypeVersion\xa1\x031.0\xa1\x0dOperationType\xa1\x06Create\x00Su\xa0\x87@\x06string\x083http://schemas.microsoft.com/2003/10/Serialization/\x99H{"id": 1,"name": "A .net door","price": 12.50,"tags": ["home", "green"]}"

我有以下属性文件servicebus.properties:

# Set the InitialContextFactory class to use
java.naming.factory.initial = org.apache.qpid.jms.jndi.JmsInitialContextFactory

# Define the required ConnectionFactory instances
# connectionfactory.<JNDI-lookup-name> = <URI>
connectionfactory.myFactoryLookup = amqps://demo-sandbox-open-bus.servicebus.windows.net?amqp.idleTimeout=150000&amqp.traceFrames=true&jms.username=somePolicy&jms.password=aM1k3PaXY5jdIkmGKm7G%2FcH%2BUFQaFAgHIYc3dSsuiLI%3D

# Register some queues in JNDI using the form
# queue.[jndi_name] = [physical_name]
# topic.[jndi_name] = [physical_name]
queue.myQueueLookup = queue1

我有以下类SimpleReceiver.java:

package com.demo.AzureTest;

import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Random;

public class SimpleReceiver implements MessageListener {

    private Connection connection;
    private Session receiveSession;
    private MessageConsumer receiver;
    private static Random randomGenerator = new Random(); 

    public SimpleReceiver() throws Exception {

        Context context = new InitialContext();

        ConnectionFactory cf = (ConnectionFactory) context.lookup("myFactoryLookup");
        Destination queue = (Destination) context.lookup("myQueueLookup");

        // Create Connection
        connection = cf.createConnection();
        System.out.println("connection :"+connection);

        // Create receiver-side Session, MessageConsumer,and MessageListener
        receiveSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        receiver = receiveSession.createConsumer(queue);
        if (receiver.getMessageSelector() != null){
            System.out.println("receiver.getMessageSelector(): " + receiver.getMessageSelector());
        }
        else {
            System.out.println("receiver.getMessageSelector(): is null" );
        }
        receiver.setMessageListener(this);

        connection.start();

    }

    public static void main(String[] args) {
        try {

            SimpleReceiver simpleSenderReceiver = new SimpleReceiver();
            System.out.println("Type 'exit' + [enter] to quit.");
            BufferedReader commandLine = new java.io.BufferedReader(new InputStreamReader(System.in));

            while (true) {
                String s = commandLine.readLine();
                if (s.equalsIgnoreCase("exit")) {
                    simpleSenderReceiver.close();
                    System.exit(0);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void close() throws JMSException {
        connection.close();
    }

    public void onMessage(Message message) {
        try {
            System.out.println("Received message with JMSMessageID = " + message.getJMSMessageID());
            TextMessage txtmessage = (TextMessage) message;
            System.out.println("Received message with Text = " + txtmessage.getText());
            message.acknowledge();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}  

我有以下类Sender.java:

package com.demo.QpidTest;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Sender {
    private static final int DEFAULT_COUNT = 1;
    private static final int DELIVERY_MODE = DeliveryMode.NON_PERSISTENT;
    private static Random randomGenerator = new Random();

    public static void main(String[] args) throws Exception { 
        int count = DEFAULT_COUNT;
        if (args.length == 0) {
            System.out.println("Sending up to " + count + " messages.");
        } else {
            count = Integer.parseInt(args[0]);
            System.out.println("Sending up to " + count + " messages.");
        }

        try {
            // The configuration for the Qpid InitialContextFactory has been supplied in
            // a jndi.properties file in the classpath, which results in it being picked
            // up automatically by the InitialContext constructor.
            Context context = new InitialContext();

            ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup");
            Destination queue = (Destination) context.lookup("myQueueLookup");

            Connection connection = factory.createConnection();
            connection.setExceptionListener(new MyExceptionListener());
            connection.start();

            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            MessageProducer messageProducer = session.createProducer(queue);

            long start = System.currentTimeMillis();
            for (int i = 1; i <= count; i++) {
//                TextMessage message = session.createTextMessage("Text!");
                TextMessage message = session.createTextMessage("{\"id\": 1,\"name\": \"A .net door\",\"price\": 12.50,\"tags\": [\"home\", \"green\"]}");
                long randomMessageID = randomGenerator.nextLong() >>>1;
                message.setStringProperty("TenantId", "klant");
                message.setStringProperty("EventType", "bericht");
                message.setStringProperty("EventTypeVersion", "1.0");
                message.setStringProperty("MessageType", "DocumentMessage");
                message.setStringProperty("OperationType", "Create");
                message.setStringProperty("SourceSystem", "sis_sender");
                message.setStringProperty("EnterpriseKey", "sender-lant-bericht");
                message.setJMSMessageID("ID:" + randomMessageID);



                messageProducer.send(message, DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);

                if (i % 100 == 0) {
                    System.out.println("Sent message " + i);
                }
            }

            long finish = System.currentTimeMillis();
            long taken = finish - start;
            System.out.println("Sent " + count + " messages in " + taken + "ms");

            connection.close();
        } catch (Exception exp) {
            System.out.println("Caught exception, exiting.");
            exp.printStackTrace(System.out);
            System.exit(1);
        }
    }

    private static class MyExceptionListener implements ExceptionListener {
        @Override
        public void onException(JMSException exception) {
            System.out.println("Connection ExceptionListener fired, exiting.");
            exception.printStackTrace(System.out);
            System.exit(1);
        }
    }
}

0 个答案:

没有答案