1

次のようなメッセージを送信する C++ パブリッシャーがあります。

Connection connection;
connection.open("127.0.0.1", 5672);
Session session = connection.createSession();
Message msg;
msg.setData("TestAMsg");
msg.getDeliveryProperties().setRoutingKey("test.A");
session.messageTransfer(arg::content = message, 
                         arg::destination = "amq.topic");
msg.setData("TestBMsg");
msg.getDeliveryProperties().setRoutingKey("test.B");
session.messageTransfer(arg::content = message, 
                         arg::destination = "amq.topic");

そして、私は次のようなJavaサブスクライバーを持っています:

AMQConnectionFactory connectionFactory = new 
                AMQConnectionFactory("amqp://guest:guest@myhost/test?
                                     brokerlist='tcp://127.0.0.1:5672'");
AMQConnection connection = (AMQConnection) 
                             connectionFactory.createConnection();
org.apache.qpid.jms.Session session = connection.createSession(false, 
                                             Session.AUTO_ACKNOWLEDGE);
AMQTopic destination = (AMQTopic) 
        AMQDestination.createDestination("topic://amq.topic//exclusive='false'?
                                          bindingkey='Test.A'");
MessageConsumer messageAConsumer = session.createConsumer(destination);
Message message_ = messageConsumer_.receive();

上記のコードでメッセージは受信されませんでした。これがどのように機能するのか非常に混乱していますか?消費者にとって正しい形式の bingding URL は何ですか? 私は何が欠けていますか?

4

2 に答える 2

2

コンシューマーは、プロデューサーが使用するルーティング キーとは異なるバインディング キーを指定します。

プロデューサー コード:

msg.getDeliveryProperties().setRoutingKey("test.A");

あなたの消費者コード:

AMQTopic destination = (AMQTopic) 
        AMQDestination.createDestination("topic://amq.topic//exclusive='false'?
                                          bindingkey='Test.A'");

各キーの最初の文字の大文字と小文字の違いに注意してください。プロデューサーは を使用test.Aし、コンシューマーは を使用します。Test.Aキーは大文字と小文字が区別されるため、完全に異なると見なされます。そのため、プロデューサーはメッセージを受け取りません。

于 2011-09-26T12:20:04.900 に答える
0

バインディング キーは test.# または test.* にする必要があります。

# と * の違いについては、このリンクをたどってくださいhttp://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/2/html/Messaging_User_Guide/chap-Messaging_User_Guide-Exchanges.html#sect-Messaging_User_Guide-Exchange_Types-Topic_Exchange

于 2012-03-06T08:05:13.167 に答える