Skip to content

Delivery Delay on Messages for JMS Producer

In a normal message flow, JMS messages that are sent by the JMS producer to the JMS broker are forwarded to the respective JMS consumer without any delay.

With the delivery delay messaging feature introduced with JMS 2.0, you can specify a delivery delay time value in each JMS message so that the JMS broker will not deliver the message until after the specified delivery delay has elapsed. Specifying a delivery delay is useful if there is a scenario where you do not want a message consumer to receive a message that is sent until a specified time duration has elapsed. To implement this, you need to add a delivery delay to the JMS producer so that the publisher does not deliver a message until the specified delivery delay time interval is elapsed.

The following diagram illustrates how you can use WSO2 Micro Integrator as a JMS producer and specify a delivery delay on messages when you do not want the message consumer to receive a message until a specified time duration has elapsed.

Synapse configuration

The synapse configuration for this sample scenario is as follows:

<proxy name="JMSDelivery" startOnLoad="true" trace="disable" transports="https http">
            <description/>
            <target>
                <inSequence>
                    <property name="OUT_ONLY" value="true"/>
                    <property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
                    <property action="remove" name="Content-Length" scope="transport"/>
                    <property action="remove" name="MIME-Version" scope="transport"/>
                    <property action="remove" name="Transfer-Encoding" scope="transport"/>
                    <property action="remove" name="User-Agent" scope="transport"/>
                    <property action="remove" name="Accept-Encoding" scope="transport"/>
                    <property name="messageType" scope="axis2" value="application/xml"/>
                    <property action="remove" name="Content-Type" scope="transport"/>
                    <log level="full"/>
                    <send>
                        <endpoint>
                            <address uri="jms:transport.jms.ConnectionFactory=myQueueConnectionFactory"/>
                        </endpoint>
                    </send>
                </inSequence>
                <outSequence>
                    <send/>
                </outSequence>
            </target>
            <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
</proxy>
<proxy name="JMSDeliveryDelayed" startOnLoad="true" trace="disable" transports="https http">
            <description/>
            <target>
                <inSequence>
                    <property name="OUT_ONLY" value="true"/>
                    <property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
                    <property action="remove" name="Content-Length" scope="transport"/>
                    <property action="remove" name="MIME-Version" scope="transport"/>
                    <property action="remove" name="Transfer-Encoding" scope="transport"/>
                    <property action="remove" name="User-Agent" scope="transport"/>
                    <property action="remove" name="Accept-Encoding" scope="transport"/>
                    <property name="messageType" scope="axis2" value="application/xml"/>
                    <property action="remove" name="Content-Type" scope="transport"/>
                    <property name="JMS_MESSAGE_DELAY" scope="axis2" value="10000"/>
                    <log level="full"/>
                    <send>
                        <endpoint>
                            <address uri="jms:/transport.jms.ConnectionFactory=myQueueConnectionFactory"/>
                        </endpoint>
                    </send>
                </inSequence>
                <outSequence>
                    <send/>
                </outSequence>
            </target>
            <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
</proxy>
<sequence name="main">
    <in>
        <!-- Log all messages passing through -->
       <log level="full"/>
        <!-- ensure that the default configuration only sends if it is one of samples -->
        <!-- Otherwise Synapse would be an open proxy by default (BAD!)               -->
        <filter regex="http://localhost:9000.*" source="get-property('To')">
        <!-- Send the messages where they have been sent (i.e. implicit "To" EPR) -->
        <send/>
        </filter>
   </in>
   <out>
        <send/>
   </out>
   <description>The main sequence for the message mediation</description>
</sequence>
<sequence name="fault">
    <!-- Log the message at the full log level with the ERROR_MESSAGE and the ERROR_CODE-->
    <log level="full">
        <property name="MESSAGE" value="Executing default 'fault' sequence"/>
        <property expression="get-property('ERROR_CODE')" name="ERROR_CODE"/>
        <property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE"/>
     </log>
     <!-- Drops the messages by default if there is a fault -->
    <drop/>
</sequence>
<registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
   <parameter name="cachableDuration">15000</parameter>
</registry>
<taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"/>

See the descriptions of the above configurations:

Artifact Description
Proxy Service 1 The JMSDeliveryDelayed proxy service sets a delivery delay of 10 seconds on the message that it forwards
Proxy Service 2 The JMSDelivery proxy service does not set a delivery delay on the message.
Main Sequence
Task Manager
Registry Artifact
Top