13 Ocak 2019 Pazar

SpringJMS JmsMessagingTemplate Sınıfı

Tanımlama
org.apache.activemq.spring.ActiveMQConnectionFactory yaratılır ve org.apache.activemq.pool.PooledConnectionFactory nesnesine verilir.

Bu nesne de

org.springframework.jms.connection.SingleConnectionFactory nesnesine verilir.

Örnek
Şöyle yaparız.
<bean id="targetConnectionFactory"
    class="org.apache.activemq.pool.PooledConnectionFactory">
    <property name="connectionFactory"
        ref="activeMqConnectionFactory" />
    <property name="idleTimeout" value="0" />
</bean>

<bean id="activeMqConnectionFactory"
    class="org.apache.activemq.ActiveMQConnectionFactory">
</bean>

<bean id="connectionFactory"
    class="org.springframework.jms.connection.SingleConnectionFactory">
    <property name="reconnectOnException" value="true" />
    <property name="targetConnectionFactory">
        <ref bean="targetConnectionFactory" />
    </property>
</bean>

<jee:jndi-lookup id="messagesQueueJndi"
    jndi-name="jms/queue/LogMessagesT" />

<bean id="messageReceiver "
    class="com.objectbyte.measuretemp.server.main.JmsReceiver"
    init-method="nowReceive">
    <constructor-arg ref="messagesQueueJndi" />
</bean>

<bean id="jmsMsgTemplate"
    class="org.springframework.jms.core.JmsMessagingTemplate">
    <property name="connectionFactory" ref="connectionFactory" />
</bean>
Örnek
ActiveMQ bağlantı ayarları için şöyle yaparız.
<jms:listener-container concurrency="${activemq.concurrent.consumers}" prefetch="1">
    <jms:listener destination="queue.request" response-destination="queue.response"
      ref="requestConsumer" method="onRequest"/>
</jms:listener-container>

<bean id="prefetchPolicy" class="org.apache.activemq.ActiveMQPrefetchPolicy">
        <property name="queuePrefetch" value="1" />
</bean>

<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
  <property name="brokerURL" value="${activemq.broker.url}?initialReconnectDelay=100&amp;
    maxReconnectDelay=10000&amp;startupMaxReconnectAttempts=3"/>
  <property name="prefetchPolicy" ref="prefetchPolicy"/>
</bean>
receive metodu
Şöyle yaparız.
JmsMessagingTemplate jmsMsgTemplate = ...;

Queue queue = ...;

try {
  Object o = jmsMsgTemplate.receive(this.queue);
  System.out.println(o);
} catch (Exception exc) {
  exc.printStackTrace();
}

Hiç yorum yok:

Yorum Gönder