Skip to content

Instantly share code, notes, and snippets.

@ayeshLK
Created May 21, 2024 07:40
Show Gist options
  • Save ayeshLK/6737610b3703cf567fd749cee2f9fd47 to your computer and use it in GitHub Desktop.
Save ayeshLK/6737610b3703cf567fd749cee2f9fd47 to your computer and use it in GitHub Desktop.
import ballerinax/activemq.driver as _;
import ballerinax/java.jms;
public function main() returns error? {
jms:Connection connection = check new (
initialContextFactory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory",
providerUrl = "tcp://localhost:61616"
);
jms:Session session = check connection->createSession();
jms:MessageConsumer consumer = check session.createConsumer(destination = {
'type: jms:QUEUE,
name: "test-queue"
});
jms:Message? receivedMessage1 = check consumer->receive();
if receivedMessage1 is jms:TextMessage {
// do something
}
jms:Message? receivedMessage2 = check consumer->receiveNoWait();
if receivedMessage2 is jms:TextMessage {
// do something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment