How to Receive a Message from an Apache ActiveMQ Topic with BSF4ooRexx

W/o Durability

connFactory = .bsf~new('org.apache.activemq.ActiveMQConnectionFactory')

conn = connFactory~createConnection()

sess = conn~createSession(.false, bsf.getConstant('javax.jms.Session', 'AUTO_ACKNOWLEDGE'))

dest = sess~createTopic('SampleTopic')

cons = sess~createConsumer(dest)

conn~bsf.invoke('start')

msg = cons~receive()

say msg

conn~close()

::requires 'BSF.CLS'

W/ Durability

connFactory = .bsf~new('org.apache.activemq.ActiveMQConnectionFactory')

conn = connFactory~createConnection()

conn~setClientID('SampleClient')

sess = conn~createSession(.false, bsf.getConstant('javax.jms.Session', 'AUTO_ACKNOWLEDGE'))

dest = sess~createTopic('SampleTopic')

cons = sess~createDurableSubscriber(dest, 'SampleSubscription')

conn~bsf.invoke('start')

msg = cons~receive()

say msg

conn~close()

::requires 'BSF.CLS'
Advertisements

How to Receive a Message from an Apache ActiveMQ Queue with BSF4ooRexx

connFactory = .bsf~new('org.apache.activemq.ActiveMQConnectionFactory')

conn = connFactory~createConnection()

sess = conn~createSession(.false, bsf.getConstant('javax.jms.Session', 'AUTO_ACKNOWLEDGE'))

dest = sess~createQueue('SampleQueue')

cons = sess~createConsumer(dest)

conn~bsf.invoke('start')

msg = cons~receive()

say msg

conn~close()

::requires 'BSF.CLS'

How to Send a Message to an Apache ActiveMQ Topic with BSF4ooRexx

connFactory = .bsf~new('org.apache.activemq.ActiveMQConnectionFactory')

conn = connFactory~createConnection()

sess = conn~createSession(.false, bsf.getConstant('javax.jms.Session', 'AUTO_ACKNOWLEDGE'))

dest = sess~createTopic('SampleTopic')

prod = sess~createProducer(dest)

msg = sess~createTextMessage('Simples Assim')

prod~bsf.invoke('send', msg)

conn~close()

::requires 'BSF.CLS'

How to Send a Message to an Apache ActiveMQ Queue with BSF4ooRexx

connFactory = .bsf~new('org.apache.activemq.ActiveMQConnectionFactory')

conn = connFactory~createConnection()

sess = conn~createSession(.false, bsf.getConstant('javax.jms.Session', 'AUTO_ACKNOWLEDGE'))

dest = sess~createQueue('SampleQueue')

prod = sess~createProducer(dest)

msg = sess~createTextMessage('Simples Assim')

prod~bsf.invoke('send', msg)

conn~close()

::requires 'BSF.CLS'

How to Setup JDBC Persistence in JBoss A-MQ

1) Install the Apache Commons DBCP bundle:

osgi:install mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_3

2) Install a JDBC driver.

3) Define a data source in the <JBoss A-MQ Install Dir>/etc/activemq.xml file:

<bean id="sample-ds" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <!-- any driver -->
  <property name="url" value="jdbc:mysql://localhost/sample_db"/>
  <property name="username" value="username"/>
  <property name="password" value="password"/>
</bean>

4) Change the persistence adapter in the <JBoss A-MQ Install Dir>/etc/activemq.xml file:

<persistenceAdapter>
  <jdbcPersistenceAdapter dataSource="#sample-ds"/>
</persistenceAdapter>

5) Start JBoss A-MQ.

You can find more details here.

How to Encode/Decode to Base64 with Apache Commons Codec

import static java.lang.System.out;
import static org.apache.commons.codec.binary.Base64.encodeBase64;

public final class CommonsCodecSample {

  public static void main(final String[] args) {
    out.println(encodeBase64("Simples Assim".getBytes()); // decodeBase64 for decoding
  }

}

How to Encode/Decode to Hexadecimal with Apache Commons Codec

import static java.lang.System.out;
import static org.apache.commons.codec.binary.Hex.encodeHex;

public final class CommonsCodecSample {

  public static void main(final String[] args) {
    out.println(encodeHex("Simples Assim".getBytes())); // decodeHex for decoding
  }

}