Scheduling messages with ActiveMQ 5.9.1 embedded in Tomcat 7 with Spring

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Scheduling messages with ActiveMQ 5.9.1 embedded in Tomcat 7 with Spring

Alessandro
Hi all.
I've managed to configure ActiveMQ to work either as a JNDI resource (in context.xml) or as a Spring set of beans. In either case everything works fine, excepted to have messages scheduled with a delay.

Following directions from the relevant page (https://activemq.apache.org/delay-and-schedule-message-delivery.html) I've tried to understand where to set that property (schedulerSupport="true"). As I'm using an embedded configuration, I've tried to follow the relevant link near the bottom of page https://activemq.apache.org/xml-configuration.html. That link is broken  (http://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java).

In the Spring version I've a snippet like the following:

<amq:broker useJmx="false" persistent="false">
    <amq:transportConnectors>
      <amq:transportConnector uri="tcp://localhost:0" />
    </amq:transportConnectors>
  </amq:broker>


 
  <amq:connectionFactory id="jmsConnectionFactory" brokerURL="vm://localhost"/>


In the JNDI version, resources more or less corresponding to the above beans are declared in the context.xml with a snippet like the following:


  <Resource name="jms/ConnectionFactory" auth="Container"
    type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS Connection Factory"
    factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="vm://localhost"
    brokerName="LocalActiveMQBroker" />


To schedule a delayed message I've used these lines of code:


    jmsTemplate_i.send(queue_i, new MessageCreator() {
      public Message createMessage(Session session) throws JMSException {
        TextMessage message = session.createTextMessage(message_p);
        message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
        return message;
      }});


where delay is 60000 (for 60 seconds).
But, as expected (no property set...), messages keep being delivered without any delay.

I've come to a dead end. Any help?
Thank you in advance.
Alessandro
Reply | Threaded
Open this post in threaded view
|

Re: Scheduling messages with ActiveMQ 5.9.1 embedded in Tomcat 7 with Spring

Alessandro
Ok, first thanks to anyone has restored the broken link. Now the link appearing in the page works:

http://svn.apache.org/repos/asf/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java

I'll let you know whether I manage to complete my task! :)

P.S.: I'm sorry for seeing my message posted twice, as I took care to delete the first one (declared to being not yet submitted to the mailing list) before sending the second one; I ignored messages are actually queued (couldn't they in this context? :) )
Reply | Threaded
Open this post in threaded view
|

Re: Scheduling messages with ActiveMQ 5.9.1 embedded in Tomcat 7 with Spring

Alessandro
This post was updated on .
In reply to this post by Alessandro
Ok, I've worked it out.
That link was inspiring! I understood that the Spring configuration was everything I needed. So I payed more attention to the wordings in the relevant page (I repeat it here): it's written that ActiveMQ from version 5.4 has an optional persistent scheduler (bold is mine). So, I tried to put up a persistent broker (attribute persitent = "true"), I added that attribute (schedulerSupport = "true") and everything works as expected.
For double checking it I put persistency to false and the delaying turned off.

Thank you again to anyone restored that link!

Ciao
Reply | Threaded
Open this post in threaded view
|

Re: Scheduling messages with ActiveMQ 5.9.1 embedded in Tomcat 7 with Spring

ceposta
In reply to this post by Alessandro
That option goes on the BrokerService... or the <amq:broker /> element

On Tue, May 6, 2014 at 11:44 AM, Alessandro
<[hidden email]> wrote:

> Hi all.
> I've managed to configure ActiveMQ to work either as a JNDI resource (in
> context.xml) or as a Spring set of beans. In either case everything works
> fine, excepted to have messages scheduled with a delay.
>
> Following directions from the relevant page (
> https://activemq.apache.org/delay-and-schedule-message-delivery.html
> <https://activemq.apache.org/delay-and-schedule-message-delivery.html>  )
> I've tried to understand where to set that property
> (*schedulerSupport="true"*). As I'm using an embedded configuration, I've
> tried to follow the relevant link near the bottom of page
> https://activemq.apache.org/xml-configuration.html
> <https://activemq.apache.org/xml-configuration.html>  . That link is broken
> (
> http://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java
> <http://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java>
> ).
>
> In the Spring version I've a snippet like the following:
>
> *<amq:broker useJmx="false" persistent="false">
>     <amq:transportConnectors>
>       <amq:transportConnector uri="tcp://localhost:0" />
>     </amq:transportConnectors>
>   </amq:broker>
>
>
>
>   <amq:connectionFactory id="jmsConnectionFactory"
> brokerURL="vm://localhost"/>
> *
>
> In the JNDI version, resources more or less corresponding to the above beans
> are declared in the context.xml with a snippet like the following:
>
> *
>   <Resource name="jms/ConnectionFactory" auth="Container"
>     type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS
> Connection Factory"
>     factory="org.apache.activemq.jndi.JNDIReferenceFactory"
> brokerURL="vm://localhost"
>     brokerName="LocalActiveMQBroker" />
> *
>
> To schedule a delayed message I've used these lines of code:
>
> *
>     jmsTemplate_i.send(queue_i, new MessageCreator() {
>       public Message createMessage(Session session) throws JMSException {
>         TextMessage message = session.createTextMessage(message_p);
>         message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY,
> delay);
>         return message;
>       }});
> *
>
> where delay is 60000 (for 60 seconds).
> But, as expected (no property set...), messages keep being delivered without
> any delay.
>
> I've come to a dead end. Any help?
> Thank you in advance.
> Alessandro
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Scheduling-messages-with-ActiveMQ-5-9-1-embedded-in-Tomcat-7-with-Spring-tp4680931.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.



--
Christian Posta
http://www.christianposta.com/blog
twitter: @christianposta
Reply | Threaded
Open this post in threaded view
|

Re: Scheduling messages with ActiveMQ 5.9.1 embedded in Tomcat 7 with Spring

artnaseef
In reply to this post by Alessandro
Have you considered using Quartz, or another approach to scheduling?

I like to keep scheduling outside of the messaging layer since they are very different responsibilities.  Especially with an embedded broker, any benefit with using ActiveMQ's scheduler seems to be eliminated (that is, having a scheduler running on a server separate from the application).

Think about the case of needing to perform maintenance on the scheduler (e.g. purging or suspending scheduled jobs).  With ActiveMQ, that means the ActiveMQ messaging functions may be impacted, even if only for a brief period of time.

Just something to consider.