Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd"&gt; &lt;!-- A simple and usual connection to activeMQ --&gt; &lt;bean id="activeMQConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"&gt; &lt;property name="brokerURL" value="tcp://localhost:61616"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;!-- A POJO that implements the JMS message listener --&gt; &lt;bean id="simpleMessageListener" class="MyJMSMessageListener" /&gt; &lt;!-- Cached Connection Factory to wrap the ActiveMQ connetion --&gt; &lt;bean id="cachedConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"&gt; &lt;property name="targetConnectionFactory" ref="activeMQConnectionFactory"&gt;&lt;/property&gt; &lt;property name="sessionCacheSize" value="10"&gt;&lt;/property&gt; &lt;property name="reconnectOnException" value="true"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;!-- The Spring message listener container configuration --&gt; &lt;jms:listener-container container-type="default" connection-factory="cachedConnectionFactory" acknowledge="auto"&gt; &lt;jms:listener destination="FOO.TEST" ref="simpleMessageListener" method="onMessage" /&gt; &lt;/jms:listener-container&gt; &lt;/beans&gt; </code></pre> <p>And the Java class that listens to the message itslef:</p> <pre><code>import javax.jms.Message; import javax.jms.MessageListener; public class MyJMSMessageListener implements MessageListener{ @Override public void onMessage(Message message) { // Do your work here } </code></pre> <p>}</p> <p>Starting this listener it's a matter of getting the Application Context, it will auto-start the JMS Listener once you do that.</p> <p><strong>EDIT according to the other question</strong> :</p> <p>So your system may generate (for example) 2 or even more messages delivered to the Consumers with the same productID? Well first this is rather not YOUR problem, but the application's. Even if you somehow you fix it, it is not really a fix, but it is a way to hide the problem itself. Nevertheless, if forced to provide a solution, right now, I can think of only one, the easiest, disable the concurrent consuming, sort of. Here is what I would do: Receive the messages in the Queue and have only one Consumer on that queue. Inside this Consumer I would process as little from the message as I can - take ONLY the productID and place it in some other queue. Before this you would have to always check if the productID is not already in that queue. If it is just return silently, if it is not, that means it has never been processed, thus place this message in a different Queue : Queue2 for example, and then enable concurrent consumers on the second Queue Queue2. This still has flaws though: first the productID queue should somehow be cleaned once in a while, otherwise it will grow forever, but that is that that hard. The tricky part: what if you have a productID in the productID queue, but the product came for an UPDATE in the DB and not INSERT? You should not reject it then... </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload