带有QPID 0.32客户端的RabbitMQ消息传递 [英] RabbitMQ Messaging with QPID 0.32 client

查看:120
本文介绍了带有QPID 0.32客户端的RabbitMQ消息传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用QPID Java客户端,我只能使用以下AMQAnyDestination扩展语法将通过交换传递的消息获取到绑定队列中

Using QPID Java Client i can only get messages delivered through the exchange to the bound queue using the following expanded syntax of AMQAnyDestination

Destination queue = new AMQAnyDestination( new AMQShortString("onms2"), 
                                               new AMQShortString("direct"),
                                               new AMQShortString("Simon"),
                                               true,        
                                               true,        
                                               new AMQShortString(""),
                                               false,       
                                               bindvars);

如果我尝试使用仅按以下方式指定地址的其他形式,则它不起作用:-

If i attempt to use the different form which just specifies the address as follows it doesnt work:-

Destination queue = new AMQAnyDestination("onms2/Simon");

该消息可以正常显示RabbitMQ,但没有发送.

The message hits RabbitMQ ok but is not delivered.

Qpid 0.32客户端 兔子MQ 3.5.7

Qpid 0.32 Client Rabbit MQ 3.5.7

交流机会 路由密钥Simon

Exchange onms Routing Key Simon

我一直在使用qpid示例,并如下修改ListSender示例

I have been using the qpid examples and modifying the ListSender example as below

package org.apache.qpid.example;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;

import org.apache.qpid.client.AMQAnyDestination;
import org.apache.qpid.client.AMQConnection;

import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.jms.ListMessage;


public class ListSender {

public static void main(String[] args) throws Exception
{
    Connection connection =
        new AMQConnection("amqp://simon:simon@localhost/test?brokerlist='tcp://localhost:5672'");
                                               AMQShortString a1 = new AMQShortString("");
                                               AMQShortString a2 = new AMQShortString("");
    AMQShortString[] bindvars = new AMQShortString[]{a1,a2};
    boolean is_durable = true;
    /*
    Destination queue = new AMQAnyDestination( new AMQShortString("onms2"), 
                                               new AMQShortString("direct"),
                                               new AMQShortString("Simon"),
                                               true,        
                                               true,        
                                               new AMQShortString(""),
                                               false,       
                                               bindvars);
    */

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination queue = new AMQAnyDestination("onms2/Simon");
    //Destination queue = new AMQAnyDestination("amqp:OpenNMSExchange/Taylor; {create: always}");
    //Destination queue = new AMQAnyDestination("OpenNMSExchange; {create: always}");
    MessageProducer producer = session.createProducer(queue);

ListMessage m = ((org.apache.qpid.jms.Session)session).createListMessage();
    m.setIntProperty("Id", 987654321);
    m.setStringProperty("name", "WidgetSimon");
    m.setDoubleProperty("price", 0.99);

    List<String> colors = new ArrayList<String>();
    colors.add("red");
    colors.add("green");
    colors.add("white");
    m.add(colors);

    Map<String,Double> dimensions = new HashMap<String,Double>();
    dimensions.put("length",10.2);
    dimensions.put("width",5.1);
    dimensions.put("depth",2.0);
    m.add(dimensions);

    List<List<Integer>> parts = new ArrayList<List<Integer>>();
    parts.add(Arrays.asList(new Integer[] {1,2,5}));
    parts.add(Arrays.asList(new Integer[] {8,2,5}));
   m.add(parts);

    Map<String,Object> specs = new HashMap<String,Object>();
    specs.put("colours", colors);
    specs.put("dimensions", dimensions);
    specs.put("parts", parts);
    m.add(specs);

    producer.send((Message)m);
    System.out.println("Sent: " + m);
    connection.close();
}

}

使用AMQAnyDestination的扩展格式工作时,调试日志如下所示:-

When it works using the expanded format of AMQAnyDestination the debug logs looks like this:-

163  [main] INFO  org.apache.qpid.client.AMQConnection  - Connection 1 now connected from /127.0.0.1:43298 to localhost/127.0.0.1:5672
163  [main] DEBUG org.apache.qpid.client.AMQConnection  - Are we connected:true
163  [main] DEBUG org.apache.qpid.client.AMQConnection  - Connected with ProtocolHandler Version:0-91
166  [main] DEBUG org.apache.qpid.client.AMQDestination  - Based on direct://onms2/Simon/?routingkey='Simon'&exclusive='true'&autodelete='true' the selected destination syntax is BURL
169  [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0  - Write channel open frame for channel id 1
184  [main] DEBUG org.apache.qpid.client.AMQSession  - Created session:org.apache.qpid.client.AMQSession_0_8@1d251891
186  [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler  - (1028176102)Method frame received: [ChannelOpenOkBody]
189  [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler  - (1028176102)Method frame received: [BasicQosOkBodyImpl: ]
195  [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8  - MessageProducer org.apache.qpid.client.BasicMessageProducer_0_8@668bc3d5 using publish mode : ASYNC_PUBLISH_ALL
206  [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8  - Sending content body frames to direct://onms2/Simon/?routingkey='Simon'&exclusive='true'&autodelete='true'
206  [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8  - Sending content header frame to direct://onms2/Simon/?routingkey='Simon'&exclusive='true'&autodelete='true'
207  [main] DEBUG org.apache.qpid.framing.FieldTable  - FieldTable::writeToBuffer: Writing encoded length of 67...

使用较短的语法失败时,调试日志如下所示:-

When it fails using the shorter syntax the debug log looks like this:-

149  [main] INFO  org.apache.qpid.client.AMQConnection  - Connection 1 now connected from /127.0.0.1:36940 to localhost/127.0.0.1:5672
149  [main] DEBUG org.apache.qpid.client.AMQConnection  - Are we connected:true
149  [main] DEBUG org.apache.qpid.client.AMQConnection  - Connected with ProtocolHandler Version:0-91
153  [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0  - Write channel open frame for channel id 1
169  [main] DEBUG org.apache.qpid.client.AMQSession  - Created session:org.apache.qpid.client.AMQSession_0_8@6bdf28bb
170  [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler  - (472294496)Method frame received: [ChannelOpenOkBody]
171  [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler  - (472294496)Method frame received: [BasicQosOkBodyImpl: ]
179  [main] DEBUG org.apache.qpid.client.AMQDestination  - Based on onms2/Simon the selected destination syntax is ADDR
182  [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0  - supportsIsBound: false
182  [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0  - supportsIsBound: false
182  [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0  - supportsIsBound: false
184  [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler  - (472294496)Method frame received: [ExchangeDeclareOkBodyImpl: ]
184  [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8  - MessageProducer org.apache.qpid.client.BasicMessageProducer_0_8@15975490 using publish mode : ASYNC_PUBLISH_ALL
195  [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8  - Sending content body frames to 'onms2'/'Simon'; None
195  [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8  - Sending content header frame to 'onms2'/'Simon'; None
196  [main] DEBUG org.apache.qpid.framing.FieldTable  - FieldTable::writeToBuffer: Writing encoded length of 90...
196  [main] DEBUG org.apache.qpid.framing.FieldTable  - {Id=[INT: 987654321], name=[LONG_STRING: WidgetSimon], price=[DOUBLE: 0.99], qpid.subject=[LONG_STRING: Simon], JMS_QPID_DESTTYPE=[INT: 2]}
198  [main] DEBUG org.apache.qpid.client.AMQSession  - Closing session: org.apache.qpid.client.AMQSession_0_8@6bdf28bb
198  [main] DEBUG org.apache.qpid.client.protocol.AMQProtocolSession  - closeSession called on protocol session for session 1

理想情况下,我需要使用较短的语法来工作,因为这是我正在使用的另一个使用AMQP发布消息的应用程序所使用的语言.

Ideally i need the shorter syntax to work as this is what is used by another application I am using which is posting messages using AMQP.

我怀疑我用来定义地址的语法有问题,但我看不到它是什么.

I suspect there is something incorrect with the syntax i am using to define the address but i cant see what it is.

我尝试过:-

amqp:onms2/Simon 地址:onms2/Simon

amqp:onms2/Simon ADDR:onms2/Simon

通过使用独立的Java客户端(使用qpid)以及Perl(使用net_amqp)和python(使用pika)进行测试,我已经确认Rabbit配置是正确的.所以我不这么认为.

I have confirmed the rabbit config is correct by testing using both a standalone java client using qpid and also using both perl (using net_amqp) and python (using pika). So i dont think its that.

任何支持者都感激不尽.

Any gudiance appreciated.

- 在QPID

- Found some extra configuration parameters on the QPID website i had missed When i configure the address as follows it works! onms3/Simon; {'create':'always','node':{'type':'topic'} } Detail

<name> [ / <subject> ] ; {
create: always | sender | receiver | never,
delete: always | sender | receiver | never,
assert: always | sender | receiver | never,
mode: browse | consume,
node: {
type: queue | topic,
durable: True | False,
x-declare: { ... <declare-overrides> ... },
x-bindings: [<binding_1>, ... <binding_n>]
},
link: {
name: <link-name>,
durable: True | False,
reliability: unreliable | at-most-once | at-least-once | exactly-once,
x-declare: { ... <declare-overrides> ... },
x-bindings: [<binding_1>, ... <binding_n>],
x-subscribe: { ... <subscribe-overrides> ... }
}
}

西蒙(Simon)

推荐答案

- 在QPID

- Found some extra configuration parameters on the QPID website i had missed When i configure the address as follows it works!

onms3/Simon; {'create':'always','node':{'type':'topic'} }

详细信息

<name> [ / <subject> ] ; {
create: always | sender | receiver | never,
delete: always | sender | receiver | never,
assert: always | sender | receiver | never,
mode: browse | consume,
node: {
type: queue | topic,
durable: True | False,
x-declare: { ... <declare-overrides> ... },
x-bindings: [<binding_1>, ... <binding_n>]
},
link: {
name: <link-name>,
durable: True | False,
reliability: unreliable | at-most-once | at-least-once | exactly-once,
x-declare: { ... <declare-overrides> ... },
x-bindings: [<binding_1>, ... <binding_n>],
x-subscribe: { ... <subscribe-overrides> ... }
}
}

这篇关于带有QPID 0.32客户端的RabbitMQ消息传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆