From 2d533e0b1b5f4a2e48f756bbde11ad24f7b547fa Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 28 Jul 2023 11:45:02 +0530 Subject: [PATCH 1/5] Add session-config as a enum --- ballerina/connection.bal | 6 +++--- ballerina/message_listener.bal | 6 +++--- ballerina/session.bal | 34 +++++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 17 deletions(-) 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..e008f180 100644 --- a/ballerina/session.bal +++ b/ballerina/session.bal @@ -21,13 +21,13 @@ import ballerina/jballerina.java; # # + 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 +202,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", From 75593d6eefb1e6e4193cf87c44f5b3a486849966 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 28 Jul 2023 11:45:28 +0530 Subject: [PATCH 2/5] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 6 +++--- ballerina/Dependencies.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index f86f1705..70fb0a90 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerinax" name = "java.jms" -version = "0.1.1" +version = "0.1.2" 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.1" -path = "../native/build/libs/java.jms-native-0.1.1.jar" +version = "0.1.2" +path = "../native/build/libs/java.jms-native-0.1.2-SNAPSHOT.jar" [[platform.java11.dependency]] groupId = "org.slf4j" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 0d69a655..4659ee65 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -57,7 +57,7 @@ dependencies = [ [[package]] org = "ballerinax" name = "java.jms" -version = "0.1.1" +version = "0.1.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"} From 53321d3074cb07285ca4c22ec83d249abf9e1ed2 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 28 Jul 2023 11:48:28 +0530 Subject: [PATCH 3/5] Remove unwanted documentation --- ballerina/session.bal | 2 -- 1 file changed, 2 deletions(-) diff --git a/ballerina/session.bal b/ballerina/session.bal index e008f180..b66c50fe 100644 --- a/ballerina/session.bal +++ b/ballerina/session.bal @@ -18,8 +18,6 @@ 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 & AcknowledgementMode acknowledgementMode; private final handle jmsSession; From e93ba087aab05f832c8df04329b3a22bf7ed1dfe Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 28 Jul 2023 12:04:34 +0530 Subject: [PATCH 4/5] Update documentation --- README.md | 9 +++------ ballerina/Module.md | 9 +++------ ballerina/Package.md | 9 +++------ 3 files changed, 9 insertions(+), 18 deletions(-) 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/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" From 59f72bcb19641b1aff74619501e53e7ccb11731f Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 28 Jul 2023 12:12:32 +0530 Subject: [PATCH 5/5] Fix message-property extracting logic --- .../main/java/io/ballerina/stdlib/java.jms/ConsumerUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/src/main/java/io/ballerina/stdlib/java.jms/ConsumerUtils.java b/native/src/main/java/io/ballerina/stdlib/java.jms/ConsumerUtils.java index 12b84917..4e2bba74 100644 --- a/native/src/main/java/io/ballerina/stdlib/java.jms/ConsumerUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/java.jms/ConsumerUtils.java @@ -175,7 +175,7 @@ private static BMap getMessageProperties(Message message) Iterator iterator = propertyNames.asIterator(); while (iterator.hasNext()) { String key = iterator.next(); - Object value = ((MapMessage) message).getObject(key); + Object value = message.getObjectProperty(key); messageProperties.put(StringUtils.fromString(key), getMapValue(value)); } return messageProperties;