Last active
March 14, 2019 09:44
-
-
Save riyafa/52f2aa7d432ff7f2b462d03afcf481a0 to your computer and use it in GitHub Desktop.
A publisher subscriber (pub-sub) consumer using ActiveMQ Artemis connector for Ballerina
This file contains hidden or 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/artemis; | |
import ballerina/io; | |
@artemis:ServiceConfig{ | |
queueConfig:{ | |
queueName:"my_queue", | |
addressName:"my_address", | |
routingType: artemis:MULTICAST | |
} | |
} | |
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("./some.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