Module : artemis
Module overview
This module provides the capability to connect with a ActiveMQ Artemis broker using the Core API.
Samples
Artemis Producer
The following program produces message to the Artemis broker.
import ballerina/artemis;
import ballerina/log;
artemis:Producer prod = new({host:"localhost", port:61616}, "demo");
public function main() {
var err = prod->send("Hello World!");
if (err is error) {
log:printError("Error occurred while sending message", err = err);
}
// Close the producer
if (!prod.isClosed()) {
err = prod->close();
if (err is error) {
log:printError("Error occurred closing producer", err = err);
}
}
}
Artemis consumer
The following program will consume a message from the Artemis broker.
@artemis:ServiceConfig {
queueConfig: {
queueName: "demo"
}
}
service artemisConsumer on new artemis:Listener({host:"localhost", port:61616}) {
resource function onMessage(artemis:Message message) {
var payload = message.getPayload();
if (payload is string) {
io:println("Recieved: " + payload);
}
}
}
AddressConfiguration | The ActiveMQ Artemis address related configuration. If the `autoCreated` is `false` an error will be thrown if the address does not exist. If `autocreated` is `true` and the address already exists then the `routingType` configuration would be ignored. |
ArtemisError | The Artemis error record. |
ArtemisServiceConfig | The configuration for an Artemis consumer service. |
ConnectionConfiguration | Configurations related to a Artemis `Connection`. |
EndpointConfiguration | The url configuration for `Producer` and `Consumer`. |
MessageConfiguration | Represents a message sent and/or received by ActiveMQ Artemis. |
QueueConfiguration | ActiveMQ Artemis Queue configuration. If the `autoCreated` is `false` an error will be thrown if the queue does not exist. If `autocreated` is `true` and the queue already exists then the other configurations would be ignored. |
SecureSocket | |
SessionConfiguration | Configurations related to a Artemis Session. |
Connection | Represents ActiveMQ Artemis Connection. |
Consumer | Representation of the ActiveMQ Artemis client consumer to make blocking receive calls. |
Message | Represents ActiveMQ Artemis Message. |
Producer | Represents ActiveMQ Artemis Producer. |
Session | Represents ActiveMQ Artemis Session. |
Listener | Represents ActiveMQ Artemis Listener. This is an abstraction for that includes the connection and session. Consumers are represented by the service attaching to this listener. |
ARTEMIS_ERROR_CODE | Constant for the artemis error code. |
MULTICAST | If you want your messages routed to every queue within the matching address, in a publish-subscribe manner. |
ANYCAST | If you want your messages routed to a single queue within the matching address, in a point-to-point manner. |
TEXT | The text message type. |
BYTES | The bytes message type. |
MAP | The map message type. |
STREAM | The stream message type. |
UNSUPPORTED | If the message recieved is not of the supported message type in Ballerina it will have the type as UNSUPPORTED. |
ServiceConfig |
MessageType | ActiveMQ Artemis message types. |
RoutingType | Determines how messages are sent to the queues associated with an address. |