qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakub Scholz <ja...@scholz.cz>
Subject Re: Creation of Request and Response quese
Date Fri, 20 Apr 2012 08:34:53 GMT
Hi Sumi,

I think the attached code snippet does pretty much what you need using
the JMS API. The reply to address is set as a property to the request
message in the step 6 (to the destination specified in a properties
file). The creation of the temporary response queue and its binding to
the response exchange is done when creating the receiver in step 4. It
is encoded in the destination.

/*
 * Step 1: Initializing the context based on the properties file
 */
Properties properties = new Properties();
InitialContext ctx;

properties.load(new FileInputStream("examples.properties"));
ctx = new InitialContext(properties);

/*
 * Step 2: Preparing the connection and session
 */
ConnectionFactory fact = (ConnectionFactory) ctx.lookup("connection");
Connection conn;
Session sess;
conn = fact.createConnection();
sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);

/*
 * Step 3: Creating a producer
 */
Destination requestDestination = (Destination) ctx.lookup("requestAddress");
MessageProducer requestProducer;
requestProducer = sess.createProducer(requestDestination);

/*
 * Step 4: Creating a broadcast receiver / consumer
 */
Destination responseDest = (Destination) ctx.lookup("responseAddress");
MessageConsumer responseConsumer;
responseConsumer = sess.createConsumer(responseDest);

/*
 * Step 5: Starting the connection
 */
conn.start();

/*
 * Step 6: Sending a request
 */
TextMessage message = sess.createTextMessage("<FIXML>...</FIXML>");
message.setJMSReplyTo((Destination) ctx.lookup("replyAddress"));
requestProducer.send(message);
System.out.println();
System.out.println("MESSAGE SENT:");
System.out.println("#############");
System.out.println(message.toString());
System.out.println();

/*
 * Step 7: Receiving responses - waiting 10 seconds
 */
Message msg = responseConsumer.receive(10000);
System.out.println(msg.toString());

/*
 * Step 8: Closing the connection
 */
requestProducer.close();
sess.close();
conn.close();

The example.properties file should contain something like this:

java.naming.factory.initial =
org.apache.qpid.jndi.PropertiesFileInitialContextFactory

# connectionfactory.[jndiname] = [ConnectionURL]
connectionfactory.connection =
amqp://user1:pass1@client1/?brokerlist='tcp://amqp-broker:5672'

# destination.[jndiname] = [address_string]
destination.requestAddress = request_exchange/request_rtg_key; { node:
{ type: topic }, create: never }
destination.replyAddress = response_exchange/response_rtg_key; {
create: receiver, node: {type: topic } }
destination.responseAddress = response_queue; {create: receiver,
assert: never, node: { type: queue, x-declare: { auto-delete: true,
exclusive: false, arguments: {'qpid.policy_type': ring,
'qpid.max_count': 1000, 'qpid.max_size': 1024000}}, x-bindings:
[{exchange: 'response_exchange', queue: 'response_queue', key:
'response_rtg_key'}]}}

I hope this helps you ...

Regards
Jakub

On Fri, Apr 20, 2012 at 05:22, Sumi <subha.manjunath@newedge.com> wrote:
> Hi Robbie ,
> Thank you , I am using Qpid -Java client (Qpid 0.14) , I will paste my
> requirement , might be i have not understood the requirement clearly
> Broker at realtime i would be connecting to AMQP broker
> 1.Existing objects in the broker - request exchange: "request.exchange"
> ,request queue: "req.queue"
> response exchange: "xxx.response"
>
> 2. Client creates response queue : xxx.tmp.response.queue
>
> 3. Client creates binding between response queue and response exchange
> binding key: test_routing_key
>
> 4. Client sends request to request exchange routing key of the request
> message (required): XXXXX.rk
> value of the reply-to exchange property of the request message: xxx.response
> value of the reply-to routing key property of the request message:
> test_routing_key
>
> 5. Server sends response
> routing key in the response message: test_routing_key
>
> Request exchange is Direct exchange
>
> For now i have created as below
> Producer code:
> private AMQShortString requestQueue = new AMQShortString("message_queue1");
> private AMQShortString routingKey = new AMQShortString("test_routing_key");
> private AMQShortString exchange = new AMQShortString("message_exchange1");
>
> AMQDestination destinationQueue = new AMQQueue(exchange, routingKey,
> requestQueue);
> //Bind queue
>                        session.bindQueue(requestQueue, destinationQueue.getRoutingKey(),
>                                        arguments, destinationQueue.getExchangeName(),
>                                        destinationQueue);
> and create producer to send the message
>
> My question is what should be the reply to property
> how to create reply to destination .
>
> And at my consumer class am creating  queue
> private AMQShortString responseQueue = new AMQShortString("response.queue");
> private AMQShortString routingKey = new AMQShortString("test_routing_key");
> private AMQShortString exchange = new AMQShortString("message_exchange1");
>
> session.sendCreateQueue(responseQueue, false, true, false, map);
> AMQDestination destinationQueue = new AMQQueue(exchange, routingKey,
> responseQueue);
>
> Now here i wanted to create temporary queue and give it a name , but in new
> qpid i have read that the name cannot be set and the broker creates by
> itself ,
> How to create temporary queue with name ?
> AMQQueue queue = new AMQQueue("response.exchange", "response_queue",
> Boolean.TRUE);
> this code returns null when i try to create temporary queue .. Please help
> !!!!!
>
> This is urgent task , am working on this from past one week still not
> arrived at exact solution , hence posting all the details . Please help .
> Any other info required on this please let me know
>
> Thanks
> Sumi
>
>
> --
> View this message in context: http://qpid.2158936.n2.nabble.com/Creation-of-Request-and-Response-quese-tp7479418p7483017.html
> Sent from the Apache Qpid users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>

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


Mime
View raw message