Connection to ActiveMQ broker
IExternalCommunicationService
allows Web Red Apps to open a connection to ActiveMQ broker.
It uses the STOMP protocol over websockets.
Red App
From within Web Red App we use IExternalCommunicationService.openJMSConnection(config)
to open a connection and acquire client
object.
When connection opens we can send messages to queue (sendMessageToQueue
method) or consume messages from queue (listenToQueue
method).
Check IExternalCommunicationService chapter for details about the API.
const config: JMSClientConfig = {
beforeConnect: () => {
console.log('[JMS SAMPLE] About to open connection to ActiveMQ Broker');
},
brokerURL: 'ws://34.121.113.14:61614',
onStompError: (frame) => {
console.log('[JMS SAMPLE] STOMP/WS error', frame);
},
onConnect: (frame) => {
console.log('[JMS SAMPLE] Connected!', frame);
},
connectHeaders: {
login: '',
password: ''
},
debug: (message) => { console.log('[ACTIVEMQ SAMPLE] Debug message: ', message); }
}
this.client = getService(IExternalCommunicationService).openJMSConnection(config);
const handleMessage = (message: IMessage) => {
console.log('Consumed message from JSM', message.body)
}
getService(IExternalCommunicationService).listenToQueue('testQueue', handleMessage, this.client);
getService(IExternalCommunicationService).sendMessageToQueue('Hello ActiveMQ', 'testQueue', this.client)
Example
You can see com.sabre.redapp.example3.web.jms sample for a showcase of communication between Red App and ActiveMQ broker.