[JMS&JBoss] Configurazione delle code JMS su JBoss 7

hornetQIn questo tutorial condivido la configurazione delle code JMS su JBoss 7, utilizzando HornetQ Servermodulo già presente nelle versioni 7.x di JBoss.

Nel file standalone.xml in ${JBOSS_HOME}/standalone/configuration (o nel file domain.xml, se è questo il file utilizzato per la configurazione di JBoss), aggiungere ciò che segue:

  • Inserire il modulo messaging nelle estensioni di JBoss (se non c’è), ossia all’interno del tag <extensions>.:
<extension module="org.jboss.as.messaging"/>
  • Per configurare l’hornetQ server e registrare i JNDI name delle code (sia queue che topic), occorre aggiungere un subsystem all’interno del tag <profile>:
<subsystem xmlns="urn:jboss:domain:messaging:1.4">
 <hornetq-server>
 <persistence-enabled>true</persistence-enabled>
 <security-enabled>false</security-enabled>
 <journal-file-size>102400</journal-file-size>
 <journal-min-files>2</journal-min-files>

 <connectors>
 <netty-connector name="netty" socket-binding="messaging">
 <param key="host" value="${jboss.bind.address}"/>
 </netty-connector>
 <netty-connector name="netty-throughput" socket-binding="messaging-throughput">
 <param key="host" value="${jboss.bind.address}"/>
 <param key="batch-delay" value="50"/>
 </netty-connector>
 <in-vm-connector name="in-vm" server-id="0"/>
 </connectors>

 <acceptors>
 <netty-acceptor name="netty" socket-binding="messaging"/>
 <netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
 <param key="batch-delay" value="50"/>
 <param key="direct-deliver" value="false"/>
 </netty-acceptor>
 <in-vm-acceptor name="in-vm" server-id="0"/>
 </acceptors>

 <security-settings>
 <security-setting match="#">
 <permission type="send" roles="guest"/>
 <permission type="consume" roles="guest"/>
 <permission type="createNonDurableQueue" roles="guest"/>
 <permission type="deleteNonDurableQueue" roles="guest"/>
 </security-setting>
 </security-settings>

 <address-settings>
 <address-setting match="jms.queue.testQueue">
 <dead-letter-address>jms.queue.DLQ</dead-letter-address>
 <expiry-address>jms.queue.ExpiryQueue</expiry-address>
 <redelivery-delay>0</redelivery-delay>
 <max-delivery-attempts>5</max-delivery-attempts>
 <max-size-bytes>10485760</max-size-bytes>
 <address-full-policy>BLOCK</address-full-policy>
 <message-counter-history-day-limit>10</message-counter-history-day-limit>
 </address-setting>
 
 <address-setting match="jms.queue.DLQ">
 <max-delivery-attempts>5</max-delivery-attempts>
 <max-size-bytes>10485760</max-size-bytes>
 <address-full-policy>BLOCK</address-full-policy>
 <message-counter-history-day-limit>10</message-counter-history-day-limit>
 </address-setting>
 </address-settings>

 <jms-connection-factories>
 <connection-factory name="InVmConnectionFactory">
 <connectors>
 <connector-ref connector-name="in-vm"/>
 </connectors>
 <entries>
 <entry name="java:/ConnectionFactory"/>
 </entries>
 <client-failure-check-period>2147483646</client-failure-check-period>
 <connection-ttl>-1</connection-ttl>
 <reconnect-attempts>-1</reconnect-attempts>
 </connection-factory>
 <connection-factory name="RemoteConnectionFactory">
 <connectors>
 <connector-ref connector-name="netty"/>
 </connectors>
 <entries>
 <entry name="RemoteConnectionFactory"/>
 <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
 </entries>
 <ha>true</ha>
 <block-on-acknowledge>true</block-on-acknowledge>
 <retry-interval>1000</retry-interval>
 <retry-interval-multiplier>1.0</retry-interval-multiplier>
 <reconnect-attempts>-1</reconnect-attempts>
 </connection-factory>
 <pooled-connection-factory name="hornetq-ra">
 <transaction mode="xa"/>
 <connectors>
 <connector-ref connector-name="in-vm"/>
 </connectors>
 <entries>
 <entry name="java:/JmsXA"/>
 </entries>
 <client-failure-check-period>2147483646</client-failure-check-period>
 <connection-ttl>-1</connection-ttl>
 <reconnect-attempts>-1</reconnect-attempts>
 </pooled-connection-factory>
 </jms-connection-factories>

 <jms-destinations>
 <jms-queue name="testQueue">
 <entry name="queue/TestQueue"/>
 <entry name="java:jboss/exported/jms/queues/TestQueue"/>
 </jms-queue>
 <jms-topic name="testTopic">
 <entry name="topic/MyTopic"/>
 </jms-topic>
 </jms-destinations>
 </hornetq-server>
</subsystem>
  • Aggiungere i seguenti messaging port nel tag <socket-binding-group>:
<socket-binding name="messaging" port="5445"/>
<socket-binding name="messaging-throughput" port="5455"/>
  • Immediatamente sotto il tag subsystem <subsystem xmlns=”urn:jboss:domain:ejb3:1.4″> (e prima del tag session-bean) aggiungere quanto segue:
<mdb>
    <resource-adapter-ref resource-adapter-name="hornetq-ra"/>
     <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
</mdb>
  • Sempre in <subsystem xmlns=”urn:jboss:domain:ejb3:1.4″>, controllare che in pools ci sia quanto sottolineato di seguito (altrimenti aggiungerlo):
<pools>
    <bean-instance-pools>
          <strict-max-pool name="slsb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
          <strict-max-pool name="mdb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
     </bean-instance-pools>
</pools>

NOTA 1: la porta mappata nel socket-binding (nell’esempio , la porta 5445) non deve avere restrizioni di rete.

NOTA 2. Per evitare la seguente eccezione:

11:56:54,753 WARN  [org.hornetq.jms.server] (ServerService Thread Pool — 52) HQ122017: Tried to correct invalid “host” value “0.0.0.0” for “netty” connector, but received an exception.: java.net.UnknownHostException: XXXXXXX: XXXXXXXX

Occorre mappare sul file etc/hosts la seguente regola:

0.0.0.0  HOSTNAME

Dove HOSTNAME è il nome macchina (valore restituito lanciando il comando hostname da terminale).

TEST: per verificare la correttezza della configurazione delle code JMS, basta restartare il server e verificare che non ci sia nessuna eccezione sul log server.log.

 

Configurazione delle code JMS in ambiente clusterizzato (Clustering HornetQ)

hornetq-ha-cluster

Aggiungere alla configurazione precedente quanto segue (solo in ambiente clusterizzato):

<server name="xyz" xmlns="urn:jboss:domain:1.1">
  <profile>
    ...
    <subsystem xmlns="urn:jboss:domain:messaging:1.1">
      <hornetq-server>
        ...
        <connectors>
          <netty-connector name="netty" socket-binding="messaging"/>
          ...
          <netty-connector name="server2-connector" socket-binding="messaging-server2"/>
          <netty-connector name="server3-connector" socket-binding="messaging-server3"/>
        </connectors>
        ...
        <cluster-connections>
          <cluster-connection name="default-cluster-connection">
            <address>
              jms
            </address>
            <connector-ref>
              netty
            </connector-ref>
            <retry-interval>
              500
            </retry-interval>
            <forward-when-no-consumers>
              true
            </forward-when-no-consumers>
            <static-connectors>
              <connector-ref>
                server2-connector
              </connector-ref>
              <connector-ref>
                server3-connector
              </connector-ref>
            </static-connectors>
          </cluster-connection>
        </cluster-connections>
        ...
      </hornetq-server>
    </subsystem>
    ...
  </profile>
  <socket-binding-group name="standard-sockets" default-interface="public">
    ...
    <socket-binding name="messaging" port="5445"/>
      ...
      <outbound-socket-binding name="messaging-server2">
        <remote-destination host=”#Indirizzo_Cluster_1” port="5445"/>
      </outbound-socket-binding>
      <outbound-socket-binding name="messaging-server3">
        <remote-destination host=”#Indirizzo_Cluster_2” port="5445"/>
      </outbound-socket-binding>
  </socket-binding-group>
</server>

NOTA. Sostituire gli indirizzi IP in remote-destination (in outbound-socket-binding) con quello dei nodi cluster JBoss (così come su evidenziato e commentato).

Riferimento: Clustering HornetQ – Red Hat Documentation