Created
December 8, 2018 17:42
-
-
Save JensWalter/d5b5f9435563a56a7a2c2e8be012c70e to your computer and use it in GitHub Desktop.
jms receiver in ballerina
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/jms; | |
import ballerina/log; | |
import ballerina/runtime; | |
import ballerina/io; | |
jms:Connection conn = new({ | |
initialContextFactory:"com.tibco.tibjms.naming.TibjmsInitialContextFactory", | |
providerUrl:"tcp://localhost:7222", | |
username:"admin", | |
password:"admin", | |
properties:{ | |
"java.naming.security.principal":"admin", | |
"java.naming.security.credentials":"admin" | |
}}); | |
jms:Session jmsSession = new(conn, { | |
acknowledgementMode:"AUTO_ACKNOWLEDGE" | |
}); | |
endpoint jms:QueueReceiver consumerEndpoint { | |
session:jmsSession, | |
queueName:"MyQueue" | |
}; | |
endpoint jms:QueueSender jmsProducer { | |
session: jmsSession | |
}; | |
service<jms:Consumer> jmsListener bind consumerEndpoint { | |
onMessage(endpoint consumer, jms:Message message) { | |
string msgId = check message.getMessageID(); | |
var dest= message.getReplyTo(); | |
match(dest){ | |
jms:Destination destination => { | |
log:printInfo("rcv "+msgId); | |
runtime:sleep(1000); | |
jms:Message m = check jmsSession.createTextMessage("Response text"); | |
_ = jmsProducer -> sendTo(destination, m); | |
log:printInfo("snd "+msgId); | |
} | |
error e => { | |
log:printError("error happened",err=e); | |
} | |
() => { | |
log:printInfo("no response dest found"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment