import ballerina/jms;
import ballerina/mb;
import ballerina/log;
endpoint mb:SimpleTopicPublisher topicPublisher {
    host: "localhost",
    port: 5672,
    topicPattern: "BallerinaTopic"
};public function main (string[] args) {
    mb:Message m = check topicPublisher.createTextMessage("Test Text");
    var _ = topicPublisher -> send(m);
}

MB Simple Topic Message Publisher

This example shows you how to publish a message to a topic using a JMS publisher.

import ballerina/jms;
import ballerina/mb;
import ballerina/log;
endpoint mb:SimpleTopicPublisher topicPublisher {
    host: "localhost",
    port: 5672,
    topicPattern: "BallerinaTopic"
};

Create a topic publisher

public function main (string[] args) {
    mb:Message m = check topicPublisher.createTextMessage("Test Text");

Create a Text message.

    var _ = topicPublisher -> send(m);
}

Send the Ballerina message to the JMS provider.

$ ballerina run mb-simple-topic-message-publisher.bal

To run the program, put the code in mb-simple-topic-message-publisher.bal and use $BALLERINA_HOME/bin/ballerina.