You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by eugene <eu...@gmail.com> on 2011/12/20 18:51:50 UTC
AMQP Java JMS Topic Exchange
Hello to all,
Well here is my issue, probably too easy for some of you, but anyhow.
I installed the MRG on a box and cumin. Everything seems to fine, and by
fine I mean I can send a message to a queue and retrieve it with Java JMS.
Now the issue is when trying to use the Topic Exchange.
Using cumin I created a new Topic Exchange and a new Queue, and a binding
between them : "usa.#" for example.
Now, I send a message to the topic which I crated, but how am I supposed to
set the routing key? Googling did not help (so far at least).
Here is my config:
java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory
connectionfactory.qpidConnectionfactory=amqp://guest:guest@clientid/test?brokerlist='tcp://locahost:5672'
destination.topicExchange = TopicExchange
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("/topic-properties/topic.properties"));
Context context = new InitialContext(properties);
ConnectionFactory connectionFactory = (ConnectionFactory)
context.lookup("qpidConnectionfactory");
Connection connection = connectionFactory.createConnection();
connection.start();
Session
session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
Destination destination = (Destination)
context.lookup("topicExchange");
MessageProducer messageProducer =
session.createProducer(destination);
MessageConsumer messageConsumer =
session.createConsumer(destination);
TextMessage message = session.createTextMessage("Hello world!");
messageProducer.send(message);
message.setStringProperty("x-amqp-0-10.routing-key", "usa.news");
message = (TextMessage)messageConsumer.receive();
System.out.println(message.getText());
connection.close();
context.close();
Can anyone plz suggest a way?
Thx! Eugene
--
View this message in context: http://apache-qpid-developers.2158895.n2.nabble.com/AMQP-Java-JMS-Topic-Exchange-tp7112690p7112690.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
Re: AMQP Java JMS Topic Exchange
Posted by Rajith Attapattu <ra...@gmail.com>.
On Thu, Dec 22, 2011 at 4:10 AM, eugene <eu...@gmail.com> wrote:
> Aha - thx for the link. So a subject is really a routing key, right? That is
> why I missed it, cause I was looking for a routing key and not subject.
Eugene, sorry for the late reply.
The subject is mapped to the routing key when using AMQP 0-10
The addressing syntax is aimed at being protocol or version agnostic.
Please read the documentation in full to understand the address
concepts and how it maps onto the 0-10 version of the AMQP protocol.
The name specified in the link property is for the subscription queue
and the subscription queue is only created for a consumer.
In your code there is no subscriber, hence the subscription queue
never gets created.
If you add a subscriber (in your example) before the producer you will
see the queue being created, the message being put into the queue and
received by the subscriber.
Regards,
Rajith
> Here is the config file:
>
> java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory
> connectionfactory.qpidConnectionfactory=amqp://guest:guest@clientid/test?brokerlist='tcp://172.16.113.130:5672'
> destination.tempQueue = TopicExchange/usa.#; {link : {name : my-queue} }
>
>
> And here is the Java File:
>
> public class CreateQueue {
> public static void main(String[] args) {
> new CreateQueue().runTest();
> }
>
> private void runTest() {
> try {
> Properties properties = new Properties();
>
> properties.load(this.getClass().getResourceAsStream("/tempqueue-cuminless/file.properties"));
> Context context = new InitialContext(properties);
>
> ConnectionFactory connectionFactory = (ConnectionFactory)
> context.lookup("qpidConnectionfactory");
> Connection connection = connectionFactory.createConnection();
> connection.start();
>
> Session
> session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
> Destination destination = (Destination) context.lookup("tempQueue");
>
> MessageProducer messageProducer =
> session.createProducer(destination);
>
> TextMessage message = session.createTextMessage("Hello world!");
> message.setStringProperty("qpid.subject", "usa.news");
>
> messageProducer.send(message);
>
>
> connection.close();
> context.close();
> }
> catch (Exception exp) {
> exp.printStackTrace();
> }
> }
> }
>
>
> From what I understood there should be a queue created with the name
> "my-queue", but it is not created. No Exception. on the CLient side, the
> /var/log/messages is very clean, no error, no nothing. But the queue is not
> created.
>
> Cheers,
> Eugene.
>
>
>
> --
> View this message in context: http://apache-qpid-developers.2158895.n2.nabble.com/AMQP-Java-JMS-Topic-Exchange-tp7112690p7117980.html
> Sent from the Apache Qpid developers mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:dev-subscribe@qpid.apache.org
>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
Re: AMQP Java JMS Topic Exchange
Posted by eugene <eu...@gmail.com>.
Aha - thx for the link. So a subject is really a routing key, right? That is
why I missed it, cause I was looking for a routing key and not subject.
Here is the config file:
java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory
connectionfactory.qpidConnectionfactory=amqp://guest:guest@clientid/test?brokerlist='tcp://172.16.113.130:5672'
destination.tempQueue = TopicExchange/usa.#; {link : {name : my-queue} }
And here is the Java File:
public class CreateQueue {
public static void main(String[] args) {
new CreateQueue().runTest();
}
private void runTest() {
try {
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("/tempqueue-cuminless/file.properties"));
Context context = new InitialContext(properties);
ConnectionFactory connectionFactory = (ConnectionFactory)
context.lookup("qpidConnectionfactory");
Connection connection = connectionFactory.createConnection();
connection.start();
Session
session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
Destination destination = (Destination) context.lookup("tempQueue");
MessageProducer messageProducer =
session.createProducer(destination);
TextMessage message = session.createTextMessage("Hello world!");
message.setStringProperty("qpid.subject", "usa.news");
messageProducer.send(message);
connection.close();
context.close();
}
catch (Exception exp) {
exp.printStackTrace();
}
}
}
>From what I understood there should be a queue created with the name
"my-queue", but it is not created. No Exception. on the CLient side, the
/var/log/messages is very clean, no error, no nothing. But the queue is not
created.
Cheers,
Eugene.
--
View this message in context: http://apache-qpid-developers.2158895.n2.nabble.com/AMQP-Java-JMS-Topic-Exchange-tp7112690p7117980.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
Re: AMQP Java JMS Topic Exchange
Posted by Rajith Attapattu <ra...@gmail.com>.
On Wed, Dec 21, 2011 at 5:59 AM, eugene <eu...@gmail.com> wrote:
> Hello Rajith,
>
> Thank you for your answers indeed it helped a lot.
>
> I still have a few questions if I may :-)
>
> 1. Why isn't this documented? I mean may be it is but I googled a lot
> yesterday and did not find much :(
Have you looked at ?
http://qpid.apache.org/books/0.12/Programming-In-Apache-Qpid/html/index.html
> 2. destination.my-queue = TopicExchange/usa.# --> you said it will create a
> temp queue. And by temp you mean by the name of "temp"? Or temporary? And if
> "temp" then nothing is created, I do a "list queue" with qpid-tool and see
> nothing new under the queues. If you mean temporary then what is it like a
> auto-delete queue? I have tried this also (create a consumer and producer
> under the same session) and it also does not work. Could you please bring
> some light?
By temp I meant an auto-deleted queue.
> 3. I tried destination.my-queue = TopicExchange/usa.#; {link : {name :
> my-queue} }, her is how it looks:
>
> java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory
> connectionfactory.qpidConnectionfactory=amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'
> destination.tempQueue = TopicExchange/usa.#; {link : {name : my-queue} }
>
I just tested with above addresses and it works for me.
I tested it using spout and drain utilities.
What exactly did u mean by not work?
1. An exception being thrown?
2. Messages not received ?
If it's the latter, then could you share your log file with us?
Regards,
Rajith
> Still no luck.
>
> The rest of the things seem to work fine, so Thx a lot!
>
> Cheers,
> Eugene.
>
> --
> View this message in context: http://apache-qpid-developers.2158895.n2.nabble.com/AMQP-Java-JMS-Topic-Exchange-tp7112690p7114768.html
> Sent from the Apache Qpid developers mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:dev-subscribe@qpid.apache.org
>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
Re: AMQP Java JMS Topic Exchange
Posted by eugene <eu...@gmail.com>.
Hello Rajith,
Thank you for your answers indeed it helped a lot.
I still have a few questions if I may :-)
1. Why isn't this documented? I mean may be it is but I googled a lot
yesterday and did not find much :(
2. destination.my-queue = TopicExchange/usa.# --> you said it will create a
temp queue. And by temp you mean by the name of "temp"? Or temporary? And if
"temp" then nothing is created, I do a "list queue" with qpid-tool and see
nothing new under the queues. If you mean temporary then what is it like a
auto-delete queue? I have tried this also (create a consumer and producer
under the same session) and it also does not work. Could you please bring
some light?
3. I tried destination.my-queue = TopicExchange/usa.#; {link : {name :
my-queue} }, her is how it looks:
java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory
connectionfactory.qpidConnectionfactory=amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'
destination.tempQueue = TopicExchange/usa.#; {link : {name : my-queue} }
Still no luck.
The rest of the things seem to work fine, so Thx a lot!
Cheers,
Eugene.
--
View this message in context: http://apache-qpid-developers.2158895.n2.nabble.com/AMQP-Java-JMS-Topic-Exchange-tp7112690p7114768.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
Re: AMQP Java JMS Topic Exchange
Posted by Rajith Attapattu <ra...@gmail.com>.
Assuming your Queue name is "my-queue" and is already bound to
TopicExchange with an appropriate binding, you can do the following.
destination.my-queue = my-queue
destination.topicExchange = TopicExchange/usa.news
You create your consumer with "my-queue" and your producer with "topicExchange".
Your producer will be sending to the TopicExchange with routing key as
"usa.news"
If you need to create a producer that can sent to "TopicExchange" with
different topics, then you can do the following
destination.topicExchange = topicExchange
and in the code you can set the subject as follows,
message.setStringProperty("qpid.subject", "usa.news");
message.setStringProperty("qpid.subject", "usa.weather");
HTH
Rajith
P.S
1. Instead of using cumin/QMF you could also create your queue to the
topic exchange using the following address
destination.my-queue = TopicExchange/usa.# --> This will create a
temp queue that binds to TopicExchange using "usa.#"
destination.my-queue = TopicExchange/usa.#; {link : {name : my-queue}
} --> This will create the queue "my-queue" that binds to
TopicExchange using "usa.#"
The above is assuming that TopicExchange exists.
2. You can't use this to set the routing key
message.setStringProperty("x-amqp-0-10.routing-key", "usa.news");
The "x-amqp-0-10.routing-key" is only there to retrieve the AMQP
0-10 routing-key from an incoming message.
On Tue, Dec 20, 2011 at 12:51 PM, eugene <eu...@gmail.com> wrote:
> Hello to all,
>
> Well here is my issue, probably too easy for some of you, but anyhow.
>
> I installed the MRG on a box and cumin. Everything seems to fine, and by
> fine I mean I can send a message to a queue and retrieve it with Java JMS.
>
> Now the issue is when trying to use the Topic Exchange.
>
> Using cumin I created a new Topic Exchange and a new Queue, and a binding
> between them : "usa.#" for example.
>
> Now, I send a message to the topic which I crated, but how am I supposed to
> set the routing key? Googling did not help (so far at least).
>
> Here is my config:
>
> java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory
> connectionfactory.qpidConnectionfactory=amqp://guest:guest@clientid/test?brokerlist='tcp://locahost:5672'
> destination.topicExchange = TopicExchange
>
>
> Properties properties = new Properties();
>
> properties.load(this.getClass().getResourceAsStream("/topic-properties/topic.properties"));
> Context context = new InitialContext(properties);
>
> ConnectionFactory connectionFactory = (ConnectionFactory)
> context.lookup("qpidConnectionfactory");
> Connection connection = connectionFactory.createConnection();
> connection.start();
>
> Session
> session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
> Destination destination = (Destination)
> context.lookup("topicExchange");
>
>
> MessageProducer messageProducer =
> session.createProducer(destination);
> MessageConsumer messageConsumer =
> session.createConsumer(destination);
>
> TextMessage message = session.createTextMessage("Hello world!");
> messageProducer.send(message);
>
> message.setStringProperty("x-amqp-0-10.routing-key", "usa.news");
>
> message = (TextMessage)messageConsumer.receive();
> System.out.println(message.getText());
>
> connection.close();
> context.close();
>
>
> Can anyone plz suggest a way?
>
> Thx! Eugene
>
> --
> View this message in context: http://apache-qpid-developers.2158895.n2.nabble.com/AMQP-Java-JMS-Topic-Exchange-tp7112690p7112690.html
> Sent from the Apache Qpid developers mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:dev-subscribe@qpid.apache.org
>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
Re: AMQP Java JMS Topic Exchange
Posted by eugene <eu...@gmail.com>.
Thx a lot!
I guess you are right, I will go through the documentation a bit more.
Thank you for your help.
Eugene.
--
View this message in context: http://apache-qpid-developers.2158895.n2.nabble.com/AMQP-Java-JMS-Topic-Exchange-tp7112690p7126163.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org