Skip to content

Commit

Permalink
Merge pull request #81 from ayeshLK/session_config
Browse files Browse the repository at this point in the history
Update session configurations
  • Loading branch information
ayeshLK committed Jul 31, 2023
2 parents 656311e + 7f83ad3 commit caaa1bd
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 41 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
9 changes: 3 additions & 6 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions ballerina/connection.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions ballerina/message_listener.bal
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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.
# + noLocal - if true then any messages published to the topic using this session's connection, or any other connection
# 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?;
Expand All @@ -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(
Expand Down
36 changes: 23 additions & 13 deletions ballerina/session.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit caaa1bd

Please sign in to comment.