diff --git a/README.md b/README.md index 603d695b..00effcee 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ public function main() returns error? { initialContextFactory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory", providerUrl = "tcp://localhost:61616" ); - jms:Session session = check connection->createSession({acknowledgementMode: "AUTO_ACKNOWLEDGE"}); + jms:Session session = check connection->createSession(); jms:Destination queue = check session->createQueue("MyQueue"); jms:MessageProducer producer = check session.createProducer(queue); jms:TextMessage msg = { @@ -60,7 +60,7 @@ public function main() returns error? { initialContextFactory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory", providerUrl = "tcp://localhost:61616" ); - jms:Session session = check connection->createSession({acknowledgementMode: "AUTO_ACKNOWLEDGE"}); + jms:Session session = check connection->createSession(); jms:Destination queue = check session->createQueue("MyQueue"); jms:MessageConsumer consumer = check session.createConsumer(queue); @@ -88,10 +88,7 @@ service "consumer-service" on new jms:Listener( connectionConfig = { initialContextFactory: "org.apache.activemq.jndi.ActiveMQInitialContextFactory", providerUrl: "tcp://localhost:61616" - }, - sessionConfig = { - acknowledgementMode: "AUTO_ACKNOWLEDGE" - }, + } destination = { 'type: jms:QUEUE, name: "MyQueue" diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index c2705596..4ad991c9 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerinax" name = "java.jms" -version = "0.1.2" +version = "0.1.3" authors = ["Ballerina"] keywords = ["jms"] repository = "https://github.com/ballerina-platform/module-ballerina-java.jms" @@ -12,8 +12,8 @@ distribution = "2201.6.0" [[platform.java11.dependency]] groupId = "io.ballerina.stdlib" artifactId = "java.jms-native" -version = "0.1.2" -path = "../native/build/libs/java.jms-native-0.1.2.jar" +version = "0.1.3" +path = "../native/build/libs/java.jms-native-0.1.3-SNAPSHOT.jar" [[platform.java11.dependency]] groupId = "org.slf4j" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 4659ee65..3ce726a5 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -57,7 +57,7 @@ dependencies = [ [[package]] org = "ballerinax" name = "java.jms" -version = "0.1.2" +version = "0.1.3" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"} diff --git a/ballerina/Module.md b/ballerina/Module.md index 42ad2d0a..751031a7 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -33,7 +33,7 @@ public function main() returns error? { initialContextFactory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory", providerUrl = "tcp://localhost:61616" ); - jms:Session session = check connection->createSession({acknowledgementMode: "AUTO_ACKNOWLEDGE"}); + jms:Session session = check connection->createSession(); jms:Destination queue = check session->createQueue("MyQueue"); jms:MessageProducer producer = check session.createProducer(queue); jms:TextMessage msg = { @@ -55,7 +55,7 @@ public function main() returns error? { initialContextFactory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory", providerUrl = "tcp://localhost:61616" ); - jms:Session session = check connection->createSession({acknowledgementMode: "AUTO_ACKNOWLEDGE"}); + jms:Session session = check connection->createSession(); jms:Destination queue = check session->createQueue("MyQueue"); jms:MessageConsumer consumer = check session.createConsumer(queue); @@ -83,10 +83,7 @@ service "consumer-service" on new jms:Listener( connectionConfig = { initialContextFactory: "org.apache.activemq.jndi.ActiveMQInitialContextFactory", providerUrl: "tcp://localhost:61616" - }, - sessionConfig = { - acknowledgementMode: "AUTO_ACKNOWLEDGE" - }, + } destination = { 'type: jms:QUEUE, name: "MyQueue" diff --git a/ballerina/Package.md b/ballerina/Package.md index 02ff3f93..796ad3be 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -32,7 +32,7 @@ public function main() returns error? { initialContextFactory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory", providerUrl = "tcp://localhost:61616" ); - jms:Session session = check connection->createSession({acknowledgementMode: "AUTO_ACKNOWLEDGE"}); + jms:Session session = check connection->createSession(); jms:Destination queue = check session->createQueue("MyQueue"); jms:MessageProducer producer = check session.createProducer(queue); jms:TextMessage msg = { @@ -54,7 +54,7 @@ public function main() returns error? { initialContextFactory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory", providerUrl = "tcp://localhost:61616" ); - jms:Session session = check connection->createSession({acknowledgementMode: "AUTO_ACKNOWLEDGE"}); + jms:Session session = check connection->createSession(); jms:Destination queue = check session->createQueue("MyQueue"); jms:MessageConsumer consumer = check session.createConsumer(queue); @@ -82,10 +82,7 @@ service "consumer-service" on new jms:Listener( connectionConfig = { initialContextFactory: "org.apache.activemq.jndi.ActiveMQInitialContextFactory", providerUrl: "tcp://localhost:61616" - }, - sessionConfig = { - acknowledgementMode: "AUTO_ACKNOWLEDGE" - }, + } destination = { 'type: jms:QUEUE, name: "MyQueue" diff --git a/ballerina/connection.bal b/ballerina/connection.bal index 9e831a63..5b670038 100644 --- a/ballerina/connection.bal +++ b/ballerina/connection.bal @@ -36,10 +36,10 @@ public isolated client class Connection { # Create a Session object, specifying transacted and acknowledgeMode # - # + sessionConfig - SessionConfiguration record consist with JMS session config + # + acknowledgementMode - Configuration indicating how messages received by the session will be acknowledged # + return - Returns the Session or an error if it fails. - isolated remote function createSession(SessionConfiguration sessionConfig) returns Session|error { - return new Session(self.jmsConnection, sessionConfig); + isolated remote function createSession(AcknowledgementMode acknowledgementMode = AUTO_ACKNOWLEDGE) returns Session|error { + return new Session(self.jmsConnection, acknowledgementMode); } # Starts (or restarts) a connection's delivery of incoming messages. diff --git a/ballerina/message_listener.bal b/ballerina/message_listener.bal index 1bc3e164..f2863d78 100644 --- a/ballerina/message_listener.bal +++ b/ballerina/message_listener.bal @@ -37,7 +37,7 @@ public enum JmsDestinationType { # Message consumer configurations. # # + connectionConfig - Configurations related to the broker connection -# + sessionConfig - Configurations related to the JMS session +# + acknowledgementMode - Configuration indicating how messages received by the session will be acknowledged # + destination - Name of the JMS destination # + messageSelector - only messages with properties matching the message selector expression are added to the durable subscription. # An empty string indicates that there is no message selector for the durable subscription. @@ -45,7 +45,7 @@ public enum JmsDestinationType { # with the same client identifier, will not be added to the durable subscription. public type ConsumerConfiguration record {| ConnectionConfiguration connectionConfig; - SessionConfiguration sessionConfig; + AcknowledgementMode acknowledgementMode = AUTO_ACKNOWLEDGE; record {| JmsDestinationType 'type; string name?; @@ -63,7 +63,7 @@ public isolated class Listener { # + consumer - The relevant JMS consumer. public isolated function init(*ConsumerConfiguration consumerConfig) returns error? { Connection connection = check new (consumerConfig.connectionConfig); - Session session = check connection->createSession(consumerConfig.sessionConfig); + Session session = check connection->createSession(consumerConfig.acknowledgementMode); Destination destination = check createJmsDestination( session, consumerConfig.destination.'type, consumerConfig.destination?.name); self.consumer = check session.createConsumer( diff --git a/ballerina/session.bal b/ballerina/session.bal index fdb62226..b66c50fe 100644 --- a/ballerina/session.bal +++ b/ballerina/session.bal @@ -18,16 +18,14 @@ import ballerina/log; import ballerina/jballerina.java; # Represents the JMS session. -# -# + config - Stores the configurations related to a JMS session. public isolated client class Session { - private final readonly & SessionConfiguration config; + private final readonly & AcknowledgementMode acknowledgementMode; private final handle jmsSession; # The default constructor of the JMS session. - public isolated function init(handle jmsConnection, SessionConfiguration sessionConfig) returns error? { - self.config = sessionConfig.cloneReadOnly(); - handle ackModeJString = java:fromString(self.config.acknowledgementMode); + public isolated function init(handle jmsConnection, AcknowledgementMode acknowledgementMode) returns error? { + self.acknowledgementMode = acknowledgementMode; + handle ackModeJString = java:fromString(self.acknowledgementMode); self.jmsSession = check createJmsSession(jmsConnection, ackModeJString); } @@ -202,13 +200,25 @@ public isolated client class Session { } } -# The Configurations that are related to a JMS session. -# -# + acknowledgementMode - Specifies the session mode that will be used. Valid values are "AUTO_ACKNOWLEDGE", -# "CLIENT_ACKNOWLEDGE", "SESSION_TRANSACTED", and "DUPS_OK_ACKNOWLEDGE". -public type SessionConfiguration record {| - string acknowledgementMode = "AUTO_ACKNOWLEDGE"; -|}; +# Defines the JMS session acknowledgement modes. +public enum AcknowledgementMode { + # Indicates that the session will use a local transaction which may subsequently + # be committed or rolled back by calling the session's `commit` or `rollback` methods. + SESSION_TRANSACTED = "SESSION_TRANSACTED", + # Indicates that the session automatically acknowledges a client's receipt of a message + # either when the session has successfully returned from a call to `receive` or when + # the message listener the session has called to process the message successfully returns. + AUTO_ACKNOWLEDGE = "AUTO_ACKNOWLEDGE", + # Indicates that the client acknowledges a consumed message by calling the + # MessageConsumer's or Caller's `acknowledge` method. Acknowledging a consumed message + # acknowledges all messages that the session has consumed. + CLIENT_ACKNOWLEDGE = "CLIENT_ACKNOWLEDGE", + # Indicates that the session to lazily acknowledge the delivery of messages. + # This is likely to result in the delivery of some duplicate messages if the JMS provider fails, + # so it should only be used by consumers that can tolerate duplicate messages. + # Use of this mode can reduce session overhead by minimizing the work the session does to prevent duplicates. + DUPS_OK_ACKNOWLEDGE = "DUPS_OK_ACKNOWLEDGE" +} isolated function createJmsTextMessageWithText(handle session, handle text) returns handle|error = @java:Method { name: "createTextMessage",