You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by Quynh Duong <qu...@outlook.com> on 2014/07/02 11:47:08 UTC

qpid cpp pub/sub

Hi folks,
I'm a cpp developer and new to the qpid world. I have spent over a day tooling around with qpid cpp api and I was wondering how can I create a pub/sub model, since all the examples that come with the package doesn't give any hints on how it can be done. Things like binding-keys and such that exist on the JMS client doesn't seem to be available in the cpp api, or I must have overlooked. I am running and building all this on CentOS 6.5.
Please help, thank you.
Quynh 		 	   		  

RE: qpid cpp pub/sub

Posted by "Duong Quynh (FSU1.Z8.IP)" <Qu...@fsoft.com.vn>.
Thank you very much Gordon, all resolved successfully.

Q

-----Original Message-----
From: Gordon Sim [mailto:gsim@redhat.com] 
Sent: Thursday, July 03, 2014 3:28 PM
To: dev@qpid.apache.org
Subject: Re: qpid cpp pub/sub

On 07/03/2014 04:42 AM, Quynh Duong wrote:
> //C++ Consumer
> string address = "topic://usa.news"; //tried all possible combo 
> including "usa.news" alone

You need to have nested quotes, i.e.

   string address = "'topic://usa.news'";

The qpid::messaging address scheme treats '/' as a separator between node name and subject. To have a node name that includes a '/' you need to quote the whole name.

[...]
> On a related note, the following connection URL on Java works with JBOSS A-MQ authentication:
> amqp://guest:guest@localhost:5672
>
> while c++ connection options:
> {username: guest, password: guest, protocol: amqp1.0} will fail at 
> authentication with message from broker:
> username [null] or invalid password

Try adding sasl_mechanisms:PLAIN to your connection options.

If that still fails can you get a protocol trace (e.g. export QPID_LOG_ENABLE=trace+:Protocol before running) for the failed connection attempt?


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org For additional commands, e-mail: dev-help@qpid.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


Re: qpid cpp pub/sub

Posted by Gordon Sim <gs...@redhat.com>.
On 07/03/2014 04:42 AM, Quynh Duong wrote:
> //C++ Consumer
> string address = "topic://usa.news"; //tried all possible combo including "usa.news" alone

You need to have nested quotes, i.e.

   string address = "'topic://usa.news'";

The qpid::messaging address scheme treats '/' as a separator between 
node name and subject. To have a node name that includes a '/' you need 
to quote the whole name.

[...]
> On a related note, the following connection URL on Java works with JBOSS A-MQ authentication:
> amqp://guest:guest@localhost:5672
>
> while c++ connection options:
> {username: guest, password: guest, protocol: amqp1.0}
> will fail at authentication with message from broker:
> username [null] or invalid password

Try adding sasl_mechanisms:PLAIN to your connection options.

If that still fails can you get a protocol trace (e.g. export 
QPID_LOG_ENABLE=trace+:Protocol before running) for the failed 
connection attempt?


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


RE: qpid cpp pub/sub

Posted by Quynh Duong <qu...@outlook.com>.
Hi Gordon,
I have implemented 2 Java JMS consumers based on your suggestion, using "topic://<somestuff>.<someelse>" and they worked perfectly. You can subscribe to the topics using "*" and "#" with ease. Java producer produces 2 messages for news and 2 messages for weather, total of 4. Pub/sub model worked with messages delivered to all JMS subs.
//Java Producer
Destination topic = producersession.createTopic("topic://usa.news");
Destination topic2 = producersession.createTopic("topic://usa.weather");
//Java Producer end
//Java Consumer 1
Destination topic = session.createTopic("topic://*.weather");
//Java Consumer 1 output
Hello weather!
Hello weather!
//Java Consumer 2
Destination topic = session.createTopic("topic://usa.*");
//Java Consumer 2 output
Hello news!
Hello news!
Hello weather!
Hello weather!
//C++ Consumer
string address = "topic://usa.news"; //tried all possible combo including "usa.news" alone
//C++ Consumer output
<nothing>


So based on my observation of the Qpid c++ API, there seems to be a lot of incompatibility with the JMS API or with JBOSS A-MQ. It can also simply be the case where the c++ implementation hasn't gone as far as the JMS API.
On a related note, the following connection URL on Java works with JBOSS A-MQ authentication:
amqp://guest:guest@localhost:5672

while c++ connection options:
{username: guest, password: guest, protocol: amqp1.0}
will fail at authentication with message from broker:
username [null] or invalid password

Hope that my observation is correct.
Quynh> Date: Wed, 2 Jul 2014 17:46:01 +0100
> From: gsim@redhat.com
> To: dev@qpid.apache.org
> Subject: Re: qpid cpp pub/sub
> 
> On 07/02/2014 05:29 PM, Quynh Duong wrote:
> > Hi Gordon,
> > Thanks for the prompt reply, I would like to further clarify my problem.
> > I am currently running the QPID JMS client and QPID CPP API against JBOSS A-MQ 6.1 on AMQP 1.0 protocol. I am still having trouble initiating a 1pub/2sub model where the pub is java and the sub is c++. I have tried different address options however I am still unable to emulate AMQP "private queue bound to exchange" approach to pub/sub.
> 
> Ok, in that case you need to modify the address so A-MQ knows that it is 
> a 'topic'. Instead of using "news" use "'topic://news'" in the c++ receiver.
> 
> > Also JBOSS A-MQ seems to not like subjects, since every time I add "/<subject>" to the address, the sub application will fail to receive messages.
> 
> The core AMQP 1.0 specification doesn't defined any standard filters, 
> which is what is needed over 1.0 to do subject filtering. There are some 
> extensions registered under the Apache namespace which is what the c++ 
> client uses for subject matching. However these are not supported by A-MQ.
> 
> (You could use a selector to do filtering instead if needed. There is 
> another extension registered for a JMS-style selector which you can use 
> with the qpid::messaging client and I believe A-MQ supports that filter.)
 		 	   		  

Re: qpid cpp pub/sub

Posted by Gordon Sim <gs...@redhat.com>.
On 07/02/2014 05:29 PM, Quynh Duong wrote:
> Hi Gordon,
> Thanks for the prompt reply, I would like to further clarify my problem.
> I am currently running the QPID JMS client and QPID CPP API against JBOSS A-MQ 6.1 on AMQP 1.0 protocol. I am still having trouble initiating a 1pub/2sub model where the pub is java and the sub is c++. I have tried different address options however I am still unable to emulate AMQP "private queue bound to exchange" approach to pub/sub.

Ok, in that case you need to modify the address so A-MQ knows that it is 
a 'topic'. Instead of using "news" use "'topic://news'" in the c++ receiver.

> Also JBOSS A-MQ seems to not like subjects, since every time I add "/<subject>" to the address, the sub application will fail to receive messages.

The core AMQP 1.0 specification doesn't defined any standard filters, 
which is what is needed over 1.0 to do subject filtering. There are some 
extensions registered under the Apache namespace which is what the c++ 
client uses for subject matching. However these are not supported by A-MQ.

(You could use a selector to do filtering instead if needed. There is 
another extension registered for a JMS-style selector which you can use 
with the qpid::messaging client and I believe A-MQ supports that filter.)






---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


RE: qpid cpp pub/sub

Posted by Quynh Duong <qu...@outlook.com>.
Code got messed up, resending:
//Java cod starts
//using Qpid Java client 0.28 AMQP1.0 libraries
package org.apache.qpid.amqp_1_0.jms.example;
import javax.jms.*;import javax.naming.Context;import javax.naming.InitialContext;import java.util.Hashtable;

public class Spout{
    public Spout()    {    }
    @SuppressWarnings({ "rawtypes", "unchecked" })	public static void main(String[] args)    {        try        {            Class.forName("org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
            Hashtable env = new Hashtable();            env.put("java.naming.provider.url", "hello.properties");            env.put("java.naming.factory.initial", "org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
            Context context = new InitialContext(env);                        ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("localhost");            Connection connection = connectionFactory.createConnection();                       connection.start();            
            Session producersession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);            Destination topic = producersession.createTopic("news");//if i change the address to "news/somestuff" sub can't see, even if addresses match
            int count = 2;
            MessageProducer producer = producersession.createProducer(topic);                                 for (int i=0; i < count; i++)            {            	Message msg = producersession.createTextMessage("Hello news!");                producer.send(msg);                System.out.println("\n------------- Msg -------------");                System.out.println(msg);                System.out.println("-------------------------------\n");            }            producer.close();
            connection.close();            context.close();        }        catch (Exception exp)        {            System.out.println("Caught exception: " + exp.getMessage());            exp.printStackTrace();        }    }}
//Java code ends

//C++ code starts
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Message.h>
#include <qpid/messaging/Message_io.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Session.h>
#include <iostream>
using namespace qpid::messaging;using namespace qpid::types;using namespace std;
int main(){    Connection connection;    try {        string url = "localhost:5672";        string connectionOptions = "{protocol:amqp1.0}";        string address = "news";//if i change the address to "news/somestuff" sub can't see, even if addresses match
        connection = Connection(url, connectionOptions);        connection.open();        Session session = connection.createSession();        Receiver receiver = session.createReceiver(address);        Duration timeout = 300 * Duration::SECOND;        int count = 5;        Message message;        int i = 0;
        while (receiver.fetch(message, timeout)) {            std::cout << message << std::endl;            session.acknowledge();            if (count && (++i == count))                break;        }        receiver.close();        session.close();        connection.close();        return 0;    } catch(const std::exception& error) {        std::cout << "Error: " << error.what() << std::endl;        connection.close();    }    return 1;}//C++ code ends 		 	   		  

RE: qpid cpp pub/sub

Posted by Quynh Duong <qu...@outlook.com>.
Hi Gordon,
Thanks for the prompt reply, I would like to further clarify my problem.
I am currently running the QPID JMS client and QPID CPP API against JBOSS A-MQ 6.1 on AMQP 1.0 protocol. I am still having trouble initiating a 1pub/2sub model where the pub is java and the sub is c++. I have tried different address options however I am still unable to emulate AMQP "private queue bound to exchange" approach to pub/sub.
Also JBOSS A-MQ seems to not like subjects, since every time I add "/<subject>" to the address, the sub application will fail to receive messages. Anyway here comes the code:
//Java code starts//using Qpid Java client 0.28 AMQP1.0 librariespackage org.apache.qpid.amqp_1_0.jms.example;import javax.jms.*;import javax.naming.Context;import javax.naming.InitialContext;import java.util.Hashtable;
public class Spout{    public Spout()    {    }
    @SuppressWarnings({ "rawtypes", "unchecked" })    public static void main(String[] args)    {        try        {            Class.forName("org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
            Hashtable env = new Hashtable();            env.put("java.naming.provider.url", "hello.properties");            env.put("java.naming.factory.initial", "org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
            Context context = new InitialContext(env);                        ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("localhost");            Connection connection = connectionFactory.createConnection();                       connection.start();            
            Session producersession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);            Destination topic = producersession.createTopic("news"); //if i change the address to "news/somestuff" sub can't see, even if addresses match
            int count = 2;
            MessageProducer producer = producersession.createProducer(topic);                                 for (int i=0; i < count; i++)            {            	Message msg = producersession.createTextMessage("Hello news!");                producer.send(msg);                System.out.println("\n------------- Msg -------------");                System.out.println(msg);                System.out.println("-------------------------------\n");            }            producer.close();
            connection.close();            context.close();        }        catch (Exception exp)        {            System.out.println("Caught exception: " + exp.getMessage());            exp.printStackTrace();        }    }}//Java code ends


//C++ code starts#include <qpid/messaging/Connection.h>#include <qpid/messaging/Message.h>#include <qpid/messaging/Message_io.h>#include <qpid/messaging/Receiver.h>#include <qpid/messaging/Session.h>
#include <iostream>
using namespace qpid::messaging;using namespace qpid::types;using namespace std;
int main(){    Connection connection;    try {        string url = "localhost:5672";        string connectionOptions = "{protocol:amqp1.0}";        string address = "news"; //if i change the address to "news/somestuff" sub can't see, even if addresses match
        connection = Connection(url, connectionOptions);        connection.open();        Session session = connection.createSession();        Receiver receiver = session.createReceiver(address);        Duration timeout = 300 * Duration::SECOND;        int count = 5;        Message message;        int i = 0;
        while (receiver.fetch(message, timeout)) {            std::cout << message << std::endl;            session.acknowledge();            if (count && (++i == count))                break;        }        receiver.close();        session.close();        connection.close();        return 0;    } catch(const std::exception& error) {        std::cout << "Error: " << error.what() << std::endl;        connection.close();    }    return 1;}//C++ code ends

This email is from me, Quynh D. 
This is to make sure things are not screwed up by spammers. 

> Date: Wed, 2 Jul 2014 11:09:03 +0100
> From: gsim@redhat.com
> To: dev@qpid.apache.org
> Subject: Re: qpid cpp pub/sub
> 
> On 07/02/2014 10:47 AM, Quynh Duong wrote:
> > I'm a cpp developer and new to the qpid world. I have spent over a day tooling around with qpid cpp api and I was wondering how can I create a pub/sub model, since all the examples that come with the package doesn't give any hints on how it can be done. Things like binding-keys and such that exist on the JMS client doesn't seem to be available in the cpp api, or I must have overlooked. I am running and building all this on CentOS 6.5.
> > Please help, thank you.
> 
> It depends on the broker (or equivalent) you want to run against. If you 
> are using one of the Qpid brokers, you can just send/receive to/from a 
> particular exchange.
> 
> E.g. if you specify amq.topic/*.news as the address for your receiver, 
> then you can e.g. send to amq.topic setting different subjects on the 
> message, and subjects like europe.news or usa.news would be received by 
> the receiver whereas as usa.weather would not.
> 
> A more simple case would just be using e.g. amq,fanout for both sender 
> and receivers and then all messages to the topic will be received by all 
> receivers, i.e. with no wildcard filtering.
> 
> Have a look at 
> http://qpid.apache.org/releases/qpid-0.28/programming/book/section-addresses.html 
> for a brief description, and feel free to ask any further questions you 
> have!
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
> For additional commands, e-mail: dev-help@qpid.apache.org
> 
 		 	   		  

Re: qpid cpp pub/sub

Posted by Gordon Sim <gs...@redhat.com>.
On 07/02/2014 10:47 AM, Quynh Duong wrote:
> I'm a cpp developer and new to the qpid world. I have spent over a day tooling around with qpid cpp api and I was wondering how can I create a pub/sub model, since all the examples that come with the package doesn't give any hints on how it can be done. Things like binding-keys and such that exist on the JMS client doesn't seem to be available in the cpp api, or I must have overlooked. I am running and building all this on CentOS 6.5.
> Please help, thank you.

It depends on the broker (or equivalent) you want to run against. If you 
are using one of the Qpid brokers, you can just send/receive to/from a 
particular exchange.

E.g. if you specify amq.topic/*.news as the address for your receiver, 
then you can e.g. send to amq.topic setting different subjects on the 
message, and subjects like europe.news or usa.news would be received by 
the receiver whereas as usa.weather would not.

A more simple case would just be using e.g. amq,fanout for both sender 
and receivers and then all messages to the topic will be received by all 
receivers, i.e. with no wildcard filtering.

Have a look at 
http://qpid.apache.org/releases/qpid-0.28/programming/book/section-addresses.html 
for a brief description, and feel free to ask any further questions you 
have!


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org