0
votes

I have successfully configured Apache Qpid JMS client (0.41.0) in Open Liberty to send messages to an Azure Service Bus queue.

My server.xml looks like this:

<jndiObjectFactory id="servicebusfactory" libraryRef="qpidlibsid"
   className="org.apache.qpid.jms.jndi.JNDIReferenceFactory" 
   objectClassName="org.apache.qpid.jms.JmsConnectionFactory">
</jndiObjectFactory>

<jndiReferenceEntry id="qpidconnectionfactory" 
  jndiName="jms/ServiceBus" 
  factoryRef="servicebusfactory">
  <properties remoteURI="amqps://xxx.servicebus.windows.net?amqp.idleTimeout=120000&amp;amqp.traceFrames=true&;jms.username=xxxx&amp;jms.password=xxx"/>
</jndiReferenceEntry>

<jndiObjectFactory id="queuefactory" libraryRef="qpidlibsid"
  className="org.apache.qpid.jms.jndi.JNDIReferenceFactory" 
  objectClassName="org.apache.qpid.jms.JmsQueue">
</jndiObjectFactory>

<jndiReferenceEntry id="myqueue" 
  jndiName="jms/myqueue" 
  factoryRef="queuefactory">
   <properties address="myqueue" />
</jndiReferenceEntry>

Using the above server config I can send messages without issues to a Service Bus queue (using a JMS message producer).

The problem is receiving messages using a message-driven-bean. I have tried this config:

@MessageDriven(name = "processorMDB", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/myqueue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/ServiceBus"),
})

I get a warning when starting Open Liberty:

[WARNING ] CNTR4016W: The message endpoint for the processorMDB message-driven bean cannot be activated because the jms/myqueue destination is not available. The message endpoint will not receive messages until the destination becomes available.

I need some kind of activation spec I assume, but I cannot get it to work correctly.

Help or explanation on how to use the activation spec in Open Liberty is appreciated!

2

2 Answers

0
votes

You are correct that you need to configure a JMS activation spec. To do that you need to install a JMS resource adapter, which requires the jms-2.0 feature,

 <featureManager>
  <feature>jms-2.0</feature>
  <feature>mdb-3.2</feature>
  ... other features
 </featureManager>

 <resourceAdapter id="myJMSResourceAdapter" location="C:/adapters/jmsRA.rar"/>

 <jmsActivationSpec id="processorMDB">
   <properties.myJMSResourceAdapter .../>
 </jmsActivationSpec>

 <jmsQueue jndiName="jms/myqueue">
   <properties.myJMSResourceAdapter .../>  
 </jmsQueue>
0
votes

I never got the MDB to work.

I used a normal MessageListener on the JMSConsumer and it works nicely even though the Javadoc states the following:

This method must not be used in a Java EE web or EJB application. Doing so may cause a JMSRuntimeException to be thrown though this is not guaranteed.

Code is:

@Singleton
@Startup
public class CreditProcessorBeanListener {

@Resource(name = "jms/ServiceBus")
private ConnectionFactory connectionFactory;

@Resource(name = "jms/myqueue")
private Queue myqueue;
private JMSContext context;
private JMSConsumer consumer;


@PostConstruct
private void init() {
    initListener();
}

private void initListener() {
    context = connectionFactory.createContext();
    consumer = context.createConsumer(myqueue);
    consumer.setMessageListener(new MyListener());

}

@PreDestroy
private void destroy() {
    consumer.close();
    context.close();
}
}

Why is MessageListener use on the JMSConsumer not "allowed" in JavaEE? Any comments on that?