import ballerina/jms;
import ballerina/log;
jms:Connection jmsConnection = new({
initialContextFactory:"wso2mbInitialContextFactory",
providerUrl:"amqp://admin:admin@carbon/carbon?brokerlist='tcp://localhost:5672'"
});
jms:Session jmsSession = new(jmsConnection, {
acknowledgementMode:"AUTO_ACKNOWLEDGE"
});
endpoint jms:QueueReceiver queueReceiver {
session:jmsSession,
queueName:"MyQueue"
};public function main(string[] args) {
var result = queueReceiver -> receive(timeoutInMilliSeconds = 5000); match result {
jms:Message msg => {
log:printInfo("Message received " + check msg.getTextMessageContent());
}
() => {
log:printInfo("Message not received");
}
Error err => {
log:printInfo("Error receiving message. " + err.message);
}
}
}
JMS Queue Message Receiver SyncThis example shows you how to consume a message from a queue in a blocking manner. |
|
import ballerina/jms;
import ballerina/log;
|
|
jms:Connection jmsConnection = new({
initialContextFactory:"wso2mbInitialContextFactory",
providerUrl:"amqp://admin:admin@carbon/carbon?brokerlist='tcp://localhost:5672'"
});
|
Initialize a JMS connection with the provider |
jms:Session jmsSession = new(jmsConnection, {
acknowledgementMode:"AUTO_ACKNOWLEDGE"
});
|
Initialize a JMS session on top of the created connection |
endpoint jms:QueueReceiver queueReceiver {
session:jmsSession,
queueName:"MyQueue"
};
|
Initialize a queue receiver on top of the the created sessions |
public function main(string[] args) {
|
|
var result = queueReceiver -> receive(timeoutInMilliSeconds = 5000);
|
Receive a message from the JMS provider. |
match result {
jms:Message msg => {
log:printInfo("Message received " + check msg.getTextMessageContent());
}
() => {
log:printInfo("Message not received");
}
Error err => {
log:printInfo("Error receiving message. " + err.message);
}
}
}
|
|
$ ballerina run jms-queue-message-consumer-sync.bal
|
To run the program, put the code in |