I was able to a set up request/reply communication with Ballerina version 0.983.0 but I fail in version 1.2.7. Can someone please advise.
Here is the code I tried:
jms:Connection connection = check jms:createConnection(jmsConfig);
jms:Session session = check connection->createSession({acknowledgementMode: "AUTO_ACKNOWLEDGE"});
jms:Destination queue = check session->createQueue("MyQueue");
jms:Destination tempQueue = check session->createTemporaryQueue();
jms:MessageProducer producer = check session.createProducer(queue);
jms:TextMessage msg = check session.createTextMessage("Hello Ballerina!");
check producer->send(msg);
jms:MessageConsumer consumer = check session->createConsumer(tempQueue);
jms:Message? response = check consumer->receive(3000);
if (response is jms:TextMessage) {
var val = response.getText();
if (val is string) {
log:printInfo("Message received: " + val);
} else {
log:printInfo("Message received without text");
}
} else {
log:printInfo("Message received.");
}
This results in the following error:
error: java.lang.ClassCastException message=java.lang.String incompatible with javax.jms.Destination
at ballerina.java_jms.C:.src.java$$$jms.session:createJmsConsumer(/C:/src/java.jms/session.bal:343)
ballerina.java_jms.Session:createConsumer(/C:/src/java.jms/session.bal:223)
acme.jmsTest:main(main.bal:30)
When I change the destination used for the consumer to be the same as used by the producer (which is "queue") as in the samples everything works fine. So either I use the temporary queue in wrong way or there is a bug with the temporary queue.
I could reproduce the same error with Ballerina 1.2.7 and ballerina/java.jms 0.8.1 with ActiveMQ server.
I created an issue to track this. Hopefully this will be fixed in a future release.
Could you tell the message broker you used? If the use case is not broker specific there are several other messaging connector options in ballerina that you could check out.