
Leading the Way: Payara Platform Community 7 Beta Now Fully Jakarta EE 11 Certified
We’re excited to announce that Payara Platform Community 7 Beta application server is now fully certified as Jakarta EE 11 […]
In a previous blog we described how to disable the OpenMQ message broker in Payara Server. In this blog we’ll describe how to use Active MQ and send and receive messages from Payara Server.
We’ll assume a default installation of ActiveMQ downloaded installed from http://activemq.apache.org/download.html. In this blog we are using the 5.15.11 release. Which we have downloaded and unzipped and run the default installation using;
./activemq console
from within the bin directory of ActiveMQ. This will run the default ActiveMQ installation in the foreground so that we can see any log messages.
We will also create a test queue within the ActiveMQ broker. The ActiveMQ broker runs a web-console when it boots that is accessible from http://127.0.0.1:8161
Access the web console and login with the default credentials admin admin. The create a queue called TESTQ
Now we need to set up the connectivity between Payara Server and ActiveMQ. To do this we use as a standard JavaEE resource adapter. Thankfully the ActiveMQ team provide us one which can be downloaded from Maven Central at http://search.maven.org/#artifactdetails|org.apache.activemq/activemq-rar/5.15.11/rar
Download with
wget http://search.maven.org/remotecontent?filepath=org/apache/activemq/activemq-rar/5.15.11/activemq-rar-5.15.11.rar -O activemq-rar-5.15.11.rar
The rar then needs to be deployed to Payara Server.
Once it has been deployed as a Java EE connector we need to configure the connector to connect to our default broker. You can also use asadmin to deploy the rar file.
asadmin deploy --type rar activemq-rar-5.12.0.rar
First we need to create a Configuration for the resource adapter to refer to our ActiveMQ broker.
The key settings are ServerURL, UserName and Password. For an out of the box ActiveMQ configuration they should be set to;
ServerURL | tcp://127.0.0.1:61616 |
UserName | admin |
Password | admin |
The resource adapter configuration can also be created using asadmin via;
asadmin create-resource-adapter-config --property ServerUrl=tcp://127.0.0.1:61616:UserName='admin':Password='admin' activemq-rar-5.12.0
Now we need to create a JMS connection pool as shown in the screen shots below.
This can also be created using asadmin;
asadmin create-connector-connection-pool --raname activemq-rar-5.12.0 --connectiondefinition javax.jms.ConnectionFactory --ping true --isconnectvalidatereq true jms/myConnectionPool
Finally we create a JNDI mapping for our JMS Connection pool by creating a JMS resource.
Again we can also create the JNDI mapping via asadmin;
asadmin create-connector-resource --poolname jms/myConnectionPool jms/myConnectionFactory
Now we have the connection factory configured we can also create a JMS mapping to our Queue
Again we can also create this JNDI mapping using asadmin.
asadmin create-admin-object --raname activemq-rar-5.12.0 --restype javax.jms.Queue --property PhysicalName=TESTQ jms/TESTQ
We are now set to write our MDB.
Below shows the code for an MDB that listens on the queue configured in this blog within ActiveMQ. You can see that both the resource adapter, the physical name of the queue and the JNDI name are set as Activation Properties of the MDB. Note the Activation Property resourceAdapter is only available from Payara Server 4.1.153.2 onwards. If you have a version of Glassish or Payara Server prior to that you will need to specify the resource adapter in your glassfish-ejb.xml deployment descriptor.
@MessageDriven(name = "testmdb", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/TESTQ"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "TESTQ"),
@ActivationConfigProperty(propertyName = "resourceAdapter", propertyValue = "activemq-rar-5.12.0")
})
public class NewMessageBean implements MessageListener {
public NewMessageBean() {
}
@Override
public void onMessage(Message message) {
System.out.println("Got message " + message);
}
}
If you build and deploy this MDB you will see in the Active MQ console that we have a single consumer on our queue.
You can test the MDB by sending a message using the ActiveMQ console.
Once you have sent the message you can check the server log as our code just printed out the received message.
That’s it. You have successfully connected Active MQ to Payara Server. Give it a try:
Share:
We’re excited to announce that Payara Platform Community 7 Beta application server is now fully certified as Jakarta EE 11 […]
Enterprise Java applications power global commerce, healthcare, government and countless other industries. These systems must be scalable, secure and […]
May 2025 marks a monumental milestone in software development: Java turns 30. The impact of this language on the […]
Is it better ActiveMQ than Open Message Queue embedded in payara ?
Regards
Hi Alex,
ActiveMQ is not better than OpenMQ just different. Many organisations use ActiveMQ as a standalone message broker, throughout their organisation, so this article is to help those people.
Steve
Hello Steve,
I really found this post enlightening. I am however trying to use ActiveMQ as the JMS broker for EclipseLink JPA2 distributed cache coordination of my app running on a payara server.
I have ActiveMQ runnnig in a Docker container. Could you guide me (point me in a direction ) on how to configure JMS & JNDI from the glassfish-web.xml file? Or if you think there’s a better way to coordinate the distributed cache I’m opean to suggestions.
Thanks
Thank you, works great.
QUESTION: what do I have to do to “speak” AMQP with ActiveMQ using the above architecture/configuration?
Hi Pit,
If you wanted to use the above configuration to communicate with ActiveMQ over AMQP, you would need to write a JCA resource adapter for it yourself, similar to the examples in the Payara Cloud Connectors repository:
https://github.com/payara/cloud-connectors
The easiest way to communicate with ActiveMQ would be to use the Apache Qpid Proton AMQP client library, though you won’t be able to use MDBs like that:
http://qpid.apache.org/proton/
A key feature of ActiveMQ that makes it an attractive broker is that it can use many different protocols, so the easiest thing for you would be to send JMS messages to it, ensuring that you understand how the transformer will map the message headers between the two protocols.
Mike
Hi Mike,
thanks for your reply.
JMS works, just with the wunderful explanation in this blog entry.
MQTT works as well, this time following the Connector JCAs.
What AMQP now promises is transactual safety. MQTT does not have this.
So: what is the way to use AMQP in a “solid” manner – and the only way I understood is to get it run via JCA.
OR: what is the 2017-favorite of messaging adaptations/protocols to bring in TX-safety into Payara? MQTT is really lightweight – works great.
…but is missing TX safety. On the other hand I saw that AMQP is loosing popularity in the community – is this right?
Hi, when the payload of ObjectMessage is a object from a class in my domain, in this case a DTO, i get this exception:
ClassNotFoundException: Forbidden class foo.bar.ArquivoRetornoDTO!
This class is not trusted to be serialized as ObjectMessage payload.
Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes.
In the docs at http://activemq.apache.org/objectmessage.html, there are this example:
“`
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(“tcp://localhost:61616”);
factory.setTrustAllPackages(true);
“`
But in my code, I use message-driven bean like this:
“`
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = “destination”, propertyValue = PreloadArquivoRetornoItemSinteticoQueue.JNDI_QUEUE),
@ActivationConfigProperty(propertyName = “destinationType”, propertyValue = “javax.jms.Queue”),
@ActivationConfigProperty(propertyName = “maxSession”, propertyValue = “1”),
@ActivationConfigProperty(propertyName = “acknowledgeMode”, propertyValue = “Auto-acknowledge”)})
@ResourceAdapter(“activemq-rar”)
public class PreloadArquivoRetornoItemSinteticoQueue implements MessageListener {
public static final String JNDI_QUEUE = “java:/jms/preloadArquivoRetornoItemSinteticoQueue”;
@Override
public void onMessage(final Message message) {
final ObjectMessage objectMessage = (ObjectMessage) message;
final ArquivoRetornoDTO arquivoRetornoDTO = (ArquivoRetornoDTO) objectMessage.getObject();
}
}
“`
I’ve already done the suggested configuration in the documentation for the producers, however I do not know how to do it for consumers since I do not use the activemq connection factory but message-driven bean.
To producers, I added the following in the environment variables for docker instance:
“`
JAVA_OPTS: “-Dorg.apache.activemq.SERIALIZABLE_PACKAGES=*”
“`
And is OK to send messages, but not to receive. So, where can I define the message-driven to `setTrustAllPackages=true` ?
**Enviroment:**
– Wildfly 15.0.1 Final
– ActiveMQ 5.15.8
**Resource Adapter in standalone-full.xml:**
“`
activemq-rar-5.15.8.rar
XATransaction
false
activemqadmin
activemqadmin
tcp://activemq:61616
1
20
false
false
jms/preloadArquivoRetornoItemSinteticoQueue
“`
Can you help-me please?
Okay this works, but can’t it be implemented in such way, that the MDB does not need to know about the RA and the physical name?
I mean all those things are defined in the admin object, but this is not accessed (you can remove those information).
I would prefer to have the MDB just use the JNDI name for the queue. I found no way to configure a javax.jms.Destination for activemq.
Hello I have a standalone ActiveMQ running with a set of queues named as “jms/BLABLA”, then I installed the ActiveMQ RAR as connector accordingly and I have an Admin Object Resource for each queue using the same naming “jms/BLABLA”, however I am unable to ping the pool jms/ActiveMQConnectionPool with a continuous error raised for each queue:
2020-08-17 17:45:10,571 [] [] [] [DefaultMessageListenerContainer-8] ERROR o.s.j.l.DefaultMessageListenerContainer:949 – Could not refresh JMS Connection for destination ‘queue://jms/BLABLA’ – retrying using FixedBackOff{interval=5000, currentAttempts=71, maxAttempts=unlimited}. Cause: Error in allocating a connection. Cause: Could not create connection.
I would appreciate a suggestion as I am porting an existing project on Payara. Thank you.
Hi Roberto, could you please raise a Github issue with a reproducer. It is likely to be a config issue which hopefully we can help you with.
Hi Jadon, I opened an issue on ActiveMQ with some more info I obtained by setting the resource adapter logger to FINEST. Please see the issue here: https://issues.apache.org/jira/browse/AMQ-8022
It is not clear if the issue is up to payara or activemq… it is related to classloaders.
I described some workaround but it is really hard to solve this kind of problems.