You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Pico Florin <pi...@yahoo.co.uk> on 2006/10/06 11:11:58 UTC
Setting the Delivery Mode for a message
Hi!
I want to know how you can set up the delivery mode for a message that shoul be sent. I have made something like this:
T extMessage replyMessage = session.createTextMessage();
replyMessage.setText(contents);
replyMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
replyMessage.setJMSCorrelationID(requestMessage
.getJMSMessageID());
replyProducer.send(replyMessage);
System.out.println("\tDeliveryMode: "
+ replyMessage.getJMSDeliveryMode());
but the latest code still print 2, meanig DeliveryMode.PERSISTENT. Also on the client that receives the message the same mode is received. I want the same thing for the client that the messages that shoul be delivered to the server( I have a P2P architecture) to have the same delivery mode. I have made something like this:
requestMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
requestProducer.send(requestMessage);
but when I'm printing out the PERSISTENT mode is printed.
Thank you,
Florin
---------------------------------
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine
Request/Reply pattern implementation dilemma
Posted by Pico Florin <pi...@yahoo.co.uk>.
Hi!
I have a P2P architecture where clients send messages to a JMS server and they are expecting for a reply. I have seen two solutions for implemementing this:
1. The client has a predefined reply queue where it expects the reply messages from the server.
2. The client has a temporary queue it expects the reply messages from the server.
I have implemented the solution 1 and I've noticed this drawback:
If the client is shutdown and the server didn't send all reply messages for it, next time when the client is connected the server will send the unsent messages eventhough the server is set up do not keep a journal.
The question is how can I consume or discard the unsent messages in order to have the reply queue empty for the next connection of the client? How can I know when the client is shutdown (is not connected anymore to the server)?
For the soution 2 I've noticed the following:
The drawback that appears in solution 1 does't appear in this soultion, meaning when the client is shutdown and it reconnects to the server it will not receive the remained unsent messages.
A major drawback appears: you should create per each message the producer that il will send the message by using somehow this code:
(supposing that the received message from the server is msg and the producer for the replying is named replyProducer and the setup for connection, session are done it)
public void onMessage(Message msg) {
...
replyProducer = session.createProducer(msg.getJMSReplyTo());
...
This approach has a huge impact on the server memory when you send a high volume of messages even when you have just one user who is connected.
I have made a producers pool as I described for the solution one but it has a setback: each time the client is connected to the server I retain the destionation and the producer in the pool and each time is different because I use temporary queue. The producers pool is a synchronized hasmap that has as a key the destination of the for the repply message and its producer. The problem can be solved again if I can test if the client is still connected or no, thus I can free up the producer pool for unactive clients.
Any suggestions and ideas regarding this issues are well appreciated.
Thank you,
Florin
---------------------------------
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine
Re: Setting the Delivery Mode for a message
Posted by James Strachan <ja...@gmail.com>.
On 10/6/06, Pico Florin <pi...@yahoo.co.uk> wrote:
> So, shoul I understand that setDeliveryMode(int) for the Message sets the delivery mode for the message object by taking the delivery mode from the Producer doesn't it?
users are not meant to call that method - only JMS provider are -
since the provider will always call that method within the
producer.send() implementation to copy on the delivery mode from the
producer.
--
James
-------
http://radio.weblogs.com/0112098/
Re: Setting the Delivery Mode for a message
Posted by Pico Florin <pi...@yahoo.co.uk>.
So, shoul I understand that setDeliveryMode(int) for the Message sets the delivery mode for the message object by taking the delivery mode from the Producer doesn't it?
James Strachan <ja...@gmail.com> wrote: On 10/6/06, Pico Florin
wrote:
> Thank you very much Rob! It works! I don't know what is the sense of the method
> setJMSDeliveryMode() in the Message interface if it hasn't any effect or how it can be used?
Its used by the JMS provider.
see
http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html#setJMSDeliveryMode(int)
--
James
-------
http://radio.weblogs.com/0112098/
---------------------------------
Now you can scan emails quickly with a reading pane. Get the new Yahoo! Mail.
Re: Setting the Delivery Mode for a message
Posted by James Strachan <ja...@gmail.com>.
On 10/6/06, Pico Florin <pi...@yahoo.co.uk> wrote:
> Thank you very much Rob! It works! I don't know what is the sense of the method
> setJMSDeliveryMode() in the Message interface if it hasn't any effect or how it can be used?
Its used by the JMS provider.
see
http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html#setJMSDeliveryMode(int)
--
James
-------
http://radio.weblogs.com/0112098/
Re: Setting the Delivery Mode for a message
Posted by Pico Florin <pi...@yahoo.co.uk>.
Thank you very much Rob! It works! I don't know what is the sense of the method
setJMSDeliveryMode() in the Message interface if it hasn't any effect or how it can be used?
Rob Davies <ra...@gmail.com> wrote: Unfortunately this is a common mistake - in that your setting the
delivery mode on the message - it needs to be set on the producer!
On 6 Oct 2006, at 10:11, Pico Florin wrote:
> Hi!
> I want to know how you can set up the delivery mode for a
> message that shoul be sent. I have made something like this:
>
> T extMessage replyMessage = session.createTextMessage();
> replyMessage.setText(contents);
> replyMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
> replyMessage.setJMSCorrelationID(requestMessage
> .getJMSMessageID());
>
> replyProducer.send(replyMessage);
> System.out.println("\tDeliveryMode: "
> + replyMessage.getJMSDeliveryMode());
>
>
> but the latest code still print 2, meanig
> DeliveryMode.PERSISTENT. Also on the client that receives the
> message the same mode is received. I want the same thing for the
> client that the messages that shoul be delivered to the server( I
> have a P2P architecture) to have the same delivery mode. I have
> made something like this:
> requestMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
> requestProducer.send(requestMessage);
> but when I'm printing out the PERSISTENT mode is printed.
>
> Thank you,
> Florin
>
>
>
>
>
> ---------------------------------
> All new Yahoo! Mail "The new Interface is stunning in its
> simplicity and ease of use." - PC Magazine
---------------------------------
Yahoo! Messenger NEW - crystal clear PC to PC calling worldwide with voicemail
Re: Setting the Delivery Mode for a message
Posted by Rob Davies <ra...@gmail.com>.
Unfortunately this is a common mistake - in that your setting the
delivery mode on the message - it needs to be set on the producer!
On 6 Oct 2006, at 10:11, Pico Florin wrote:
> Hi!
> I want to know how you can set up the delivery mode for a
> message that shoul be sent. I have made something like this:
>
> T extMessage replyMessage = session.createTextMessage();
> replyMessage.setText(contents);
> replyMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
> replyMessage.setJMSCorrelationID(requestMessage
> .getJMSMessageID());
>
> replyProducer.send(replyMessage);
> System.out.println("\tDeliveryMode: "
> + replyMessage.getJMSDeliveryMode());
>
>
> but the latest code still print 2, meanig
> DeliveryMode.PERSISTENT. Also on the client that receives the
> message the same mode is received. I want the same thing for the
> client that the messages that shoul be delivered to the server( I
> have a P2P architecture) to have the same delivery mode. I have
> made something like this:
> requestMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
> requestProducer.send(requestMessage);
> but when I'm printing out the PERSISTENT mode is printed.
>
> Thank you,
> Florin
>
>
>
>
>
> ---------------------------------
> All new Yahoo! Mail "The new Interface is stunning in its
> simplicity and ease of use." - PC Magazine