You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by fluency <in...@gmail.com> on 2014/04/23 11:25:31 UTC

Non-persistent deliverymode not effect.

Dear all,

MQ version 5.5.0. I want to use non-persistent delivery in queue,so i make
these settings:
1.comment out persistenceAdapter in activemq.xml
2.set jmstemplate:
<bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate">  
        <property name="connectionFactory">
        	<ref local="jmsFactory"/>
        </property>
        <property name="defaultDestinationName" value="mqtest" /> 
        *<property name="deliveryPersistent" value="false"></property> *
        <property name="messageConverter">
        	<ref local="conversion" /> 
        </property>  
        <property name="pubSubDomain" value="false" />  
    </bean>
3.in producer:
 public void simpleSend(HashMapPojo pojo){
    	this.jmsTemplet.setDeliveryPersistent(false);
    	this.jmsTemplet.convertAndSend(pojo);
    	this.jmsTemplet.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    }
4.in converter:
       public Object fromMessage(Message message) throws JMSException,
			MessageConversionException {
		ObjectMessage objMsg = (ObjectMessage) message;
		objMsg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
		return objMsg;
	}

	public Message toMessage(Object obj, Session session) throws JMSException,
			MessageConversionException {
		ObjectMessage objMsg = session.createObjectMessage();
		objMsg.setJMSReplyTo(objMsg.getJMSDestination());
		objMsg.setObject((HashMapPojo) obj);
		objMsg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
		return objMsg;
	} 

But,why i'm seeing messages still persistent in MQConsole?
<http://activemq.2283324.n4.nabble.com/file/n4680457/4b3c5ac3f47d4b15a00e659064675510.jpg> 

Did i do something incorrect? Pls help, thank you for your time.



--
View this message in context: http://activemq.2283324.n4.nabble.com/Non-persistent-deliverymode-not-effect-tp4680457.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Non-persistent deliverymode not effect.

Posted by Phil White <pw...@gmail.com>.
It's a fair point, and I've used both approaches in the past, but when you're
using the Spring framework for almost everything else then it's natural to
also use its messaging abstractions, and in most cases it does simplify JMS
usage and configuration. While looking into the persistence problem I found
numerous posting about JMSTemplate's performance failings, but as detailed
in chriswongdevblog.blogspot.co.uk/2013/01/jmstemplate-is-not-evil.html the
problem often turns out to be because Spring applies defaults which aren't
optimal in many applications, and in practice it's a fairly thin shim over
the JMS API.
I suppose there are similar arguments for and against most API abstractions,
for example Spring data vs  Hibernate (or other ORM) vs JDBC vs ODBC vs
specific database APIs. If performance or fine grained control is key then
diving in at a lower level makes sense, but often the higher level
abstraction provides convenience at a small expense.



--
View this message in context: http://activemq.2283324.n4.nabble.com/Non-persistent-deliverymode-not-effect-tp4680457p4715000.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Non-persistent deliverymode not effect.

Posted by Clebert Suconic <cl...@gmail.com>.
I don't remember who was it.. but I spoke with some Spring guy some
time ago, and even him didn't like SpringTemplate. ;)


Why not simply use simple JMS API? and I'm speaking from the POV of
any JMS server. not just ActiveMQ.

On Tue, Aug 2, 2016 at 11:38 AM, Phil White <pw...@gmail.com> wrote:
> Two years on I saw the same thing, that Spring's JMSTemplate seems to ignore
> non-persistent delivery configuration, and always sends as persistent.
> Tracing through JMSTemplate it turns out that deliveryMode, priority, and
> timeToLive are ignored during send() unless "explicit QOS" is enabled, ie.
> jmsTemplate.setExplicitQosEnabled(true). Or alternatively the equivalent in
> the Spring app context:
>
>         <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
>                 <property name="connectionFactory">
>                         <ref local="jmsFactory"/>
>                 </property>
>                 <property name="pubSubDomain" value="true"/>
>                 <property name="deliveryPersistent" value="false"/>
>                 <property name="deliveryMode" value="1"/>
>                 <property name="explicitQosEnabled" value="true"/>
>         </bean>
>
> I'm sure the OP found the same thing out years ago, but just for anyone else
> with the same problem.
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Non-persistent-deliverymode-not-effect-tp4680457p4714981.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.



-- 
Clebert Suconic

Re: Non-persistent deliverymode not effect.

Posted by Phil White <pw...@gmail.com>.
Two years on I saw the same thing, that Spring's JMSTemplate seems to ignore
non-persistent delivery configuration, and always sends as persistent.
Tracing through JMSTemplate it turns out that deliveryMode, priority, and
timeToLive are ignored during send() unless "explicit QOS" is enabled, ie.
jmsTemplate.setExplicitQosEnabled(true). Or alternatively the equivalent in
the Spring app context:

	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory">
			<ref local="jmsFactory"/>
		</property>
		<property name="pubSubDomain" value="true"/>
		<property name="deliveryPersistent" value="false"/>
		<property name="deliveryMode" value="1"/>
		<property name="explicitQosEnabled" value="true"/>
	</bean>

I'm sure the OP found the same thing out years ago, but just for anyone else
with the same problem.



--
View this message in context: http://activemq.2283324.n4.nabble.com/Non-persistent-deliverymode-not-effect-tp4680457p4714981.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Non-persistent deliverymode not effect.

Posted by artnaseef <ar...@artnaseef.com>.
Is this still a problem?  I would trace into the convertAndSend() call - you
want to get down to the ActiveMQMessageProducer's send() call and verify
that it has NON_PERSISTENT mode set.

If NON_PERSISTENT mode is set on the ActiveMQMessageProducer's send() call,
and the messages are getting to the broker with PERSISTENT mode, that sounds
like a bug.  On the other hand, if they are PERSISTENT in the same send()
call, somewhere between the JMS template and the actual producer, the
setting is getting lost.



--
View this message in context: http://activemq.2283324.n4.nabble.com/Non-persistent-deliverymode-not-effect-tp4680457p4680984.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Non-persistent deliverymode not effect.

Posted by fluency <in...@gmail.com>.
Dear artnaseef, thanks for the reply.

The line of codes that sends is very simple:invoke simpleSend message in
Action.java:
for(int i=0;i<1000;i++){
    producer.simpleSend(pojo);
}
then goes to  Producer.java :
 public void simpleSend(HashMapPojo pojo){ 
    this.jmsTemplet.setDeliveryPersistent(false); 
    this.jmsTemplet.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 
    this.jmsTemplet.convertAndSend(pojo); 
    
}
I think this "convertAndSend(pojo)" is the send() call,am i right?

And i debugged both in Action.java & Producer.java as you said,the property
"deliveryMode" of jmsTemplet was always "1(NON_PERSISTENT)".




--
View this message in context: http://activemq.2283324.n4.nabble.com/Non-persistent-deliverymode-not-effect-tp4680457p4680500.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Non-persistent deliverymode not effect.

Posted by artnaseef <ar...@artnaseef.com>.
There is nothing obviously wrong in the posted snippets.  Is it possible to
use a debugging and put a break-point on the line of code that sends
(interestingly, that line of code is missing from the snippets given)?

Note that I believe this has no effect as the broker calls it internally: 
                objMsg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); 

That's as called-out in the JMS spec.  The JMS* fields are used internally
and client's changing their values has no effect.

With that said, the property on the JMS template should do the job.

Verify that either the send() call in the MessageProducer is getting passed
the NON_PERSISTENT flag, or at least that it's deliveryMode is in-fact set
to NON_PERSISTENT.



--
View this message in context: http://activemq.2283324.n4.nabble.com/Non-persistent-deliverymode-not-effect-tp4680457p4680486.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.