Skip to content

Instantly share code, notes, and snippets.

@riyafa
Last active March 14, 2019 09:44
Show Gist options
  • Save riyafa/00a0673b12d18f59a283b1eace441f56 to your computer and use it in GitHub Desktop.
Save riyafa/00a0673b12d18f59a283b1eace441f56 to your computer and use it in GitHub Desktop.
A point to point consumer using ActiveMQ Artemis connector for Ballerina
import ballerina/artemis;
import ballerina/io;
@artemis:ServiceConfig{
queueConfig:{
queueName:"my_queue"
}
}
service artemisConsumer on new artemis:Listener({host:"localhost", port:61616}){
resource function onMessage(artemis:Message message) returns error? {
var payload = message.getPayload();
if(payload is map<string>){
io:println("map<string>");
} else if(payload is map<int>){
io:println("int map");
} else if (payload is string){
io:println("string");
} else if(payload is byte[]){
io:println("byte[]");
} else if(payload is map<byte[]>){
io:println("map<byte[]>");
} else if(payload is map<boolean>){
io:println("map<boolean>");
} else if(payload is map<float>){
io:println("map<float>");
} else if(message.getType()==artemis:STREAM){
io:println("stream");
io:WritableByteChannel destinationChannel = io:openWritableFile("./tech.pdf");
check message.saveToWritableByteChannel(destinationChannel);
}
io:println(payload);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment