Results 1 to 6 of 6

Thread: non-persistent channels?

  1. #1
    Join Date
    Jun 2009
    Posts
    4

    Default non-persistent channels?

    I'm using spring integration with activemq. I don't want my messages to be persistent. I've figured out how to do this at the broker level (broker.setPersistent(false)) but I can't figure out how to do this per channel (or per topic, or per queue...)

    I assume its possible. The activemq docs say to set the the delivery mode of the MessageProducer to "NON_PERSISTENT", but I'm not creating the message producer myself. Where in this snippet can I configure the channel to be non-persistent?

    Code:
        <si-jms:outbound-channel-adapter channel="myChannel" destination="myTopic"/>
        <si:publish-subscribe-channel id="myChannel"/>
        <amq:topic id="myTopic" physicalName="myTopicName"/>
    thanks
    sam

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Sam,

    In the JMS 'outbound-channel-adapter', you can reference a JmsTemplate instead (with the 'jms-template' attribute). Then, on the JmsTemplate bean definition, you will need to set the 'destination' property (instead of having it on the 'outbound-channel-adapter'), and you will also need to set the 'connectionFactory' property reference.

    The reason for this is that the JmsTemplate exposes a few "advanced" properties that are not configurable directly on the outbound-channel-adapter (such as the deliveryMode), so if you need this level of customization, you can configure it separately and reference that bean.

    Hope that helps.
    -Mark

  3. #3
    Join Date
    May 2012
    Posts
    10

    Default problem forcing non-persistent messages in spring integration

    Hello,
    I found your advice very helpful as I have similar issue that I do not want messages to persist.
    However, regardless of configuring JmsTemplate delivery mode to non-persistent the service on the other side still reports that the message was sent as persistent.

    Here is my spring context. It may be missing something...? but what?
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:util="http://www.springframework.org/schema/util"
        xmlns:jms="http://www.springframework.org/schema/jms"
    	xmlns:si="http://www.springframework.org/schema/integration"
        xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
        xmlns:stream="http://www.springframework.org/schema/integration/stream"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
                http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
                http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-1.0.xsd
                http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
                http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-1.0.xsd" >
    
     
        <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
            <constructor-arg ref="hornetqConnectionFactory" />
            <property name="cacheProducers" value="true" />
            <property name="cacheConsumers" value="true" />
            <property name="sessionCacheSize" value="200" />
        </bean>
        
        <!--  HornetQ configuration  -->
        <bean id="hornetqConnectionFactory" class="org.hornetq.api.jms.HornetQJMSClient" factory-method="createConnectionFactoryWithoutHA">
            <constructor-arg>
                <ref bean="connectionFactoryType" />
            </constructor-arg>
            <constructor-arg>
                <list>
                    <ref bean="connectorConfig" />
                </list>
            </constructor-arg>
        </bean>
    
        <bean id="connectionFactoryType" class="org.hornetq.api.jms.JMSFactoryType" factory-method="valueOf" lazy-init="false">
            <constructor-arg value="CF" />
        </bean>
    
        <bean id="connectorConfig" class="org.hornetq.api.core.TransportConfiguration">
            <constructor-arg type="java.lang.String" value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
            <constructor-arg>
                <map key-type="java.lang.String" value-type="java.lang.Object">
                    <entry key="host" value="localhost" />
                    <entry key="port" value="5445" />
                </map>
            </constructor-arg>
        </bean>
    
        <bean id="messageTemplate"  class="org.springframework.jms.core.JmsTemplate">
                    <property name="connectionFactory" ref="connectionFactory"/>
                    <property name="deliveryPersistent" value="false" />
                    <property name="sessionAcknowledgeMode">
                        <util:constant static-field="javax.jms.Session.AUTO_ACKNOWLEDGE" />
                    </property>
        </bean>
    
        <int-jms:outbound-channel-adapter id="toBroker" channel="toJms" destination-name="impressionCounterQueue"
         jms-template="messageTemplate" />
    
        <si:channel id="toJms">
         <si:dispatcher failover="false" load-balancer="none" task-executor="asyncDispatcher"/>
            <si:interceptors>
                <si:wire-tap channel="logger"/>
            </si:interceptors>
       </si:channel>
       
       <si:logging-channel-adapter id="logger" level="DEBUG"/>
       
       <bean id="asyncDispatcher" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" >
            <property name="corePoolSize" value="1" />
            <property name="maxPoolSize" value="10" />
            <property name="queueCapacity" value="25" />
       </bean>
    </beans>
    thank you in advance for your advice

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,036

    Default

    You also need to set explicitQosEnabled to true for this to take effect...

    Code:
    	/**
    	 * Set the delivery mode to use when sending a message.
    	 * Default is the Message default: "PERSISTENT".
    	 * <p>Since a default value may be defined administratively,
    	 * this is only used when "isExplicitQosEnabled" equals "true".
    	 * @param deliveryMode the delivery mode to use
    	 * @see #isExplicitQosEnabled
    	 * @see javax.jms.DeliveryMode#PERSISTENT
    	 * @see javax.jms.DeliveryMode#NON_PERSISTENT
    	 * @see javax.jms.Message#DEFAULT_DELIVERY_MODE
    	 * @see javax.jms.MessageProducer#send(javax.jms.Message, int, int, long)
    	 */
    	public void setDeliveryMode(int deliveryMode) {
    		this.deliveryMode = deliveryMode;
    	}
    
    	/**
    	 * Set if the QOS values (deliveryMode, priority, timeToLive)
    	 * should be used for sending a message.
    	 * @see #setDeliveryMode
    	 * @see #setPriority
    	 * @see #setTimeToLive
    	 */
    	public void setExplicitQosEnabled(boolean explicitQosEnabled) {
    		this.explicitQosEnabled = explicitQosEnabled;
    	}
    I see this is not explicitly mentioned in the setter you used, but there is a @See for the method above.

    Code:
    	/**
    	 * Set whether message delivery should be persistent or non-persistent,
    	 * specified as boolean value ("true" or "false"). This will set the delivery
    	 * mode accordingly, to either "PERSISTENT" (1) or "NON_PERSISTENT" (2).
    	 * <p>Default it "true" aka delivery mode "PERSISTENT".
    	 * @see #setDeliveryMode(int)
    	 * @see javax.jms.DeliveryMode#PERSISTENT
    	 * @see javax.jms.DeliveryMode#NON_PERSISTENT
    	 */
    	public void setDeliveryPersistent(boolean deliveryPersistent) {
    		this.deliveryMode = (deliveryPersistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
    	}
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    May 2012
    Posts
    10

    Default

    Thank you, Gary, this has addressed my problem spot on.

  6. #6
    Join Date
    May 2012
    Posts
    10

    Default

    Thank you, Garry, for replying to my post. Your advice was very helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •