Skip to content

Commit

Permalink
Merge pull request #91 from ayeshLK/local_development
Browse files Browse the repository at this point in the history
Add `close` API to JMS MessageProducer
  • Loading branch information
ayeshLK authored Aug 7, 2023
2 parents a98aa6a + 0a0c40b commit 359586a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ballerina/message_producer.bal
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public isolated client class MessageProducer {
name: "sendTo",
'class: "io.ballerina.stdlib.java.jms.JmsProducer"
} external;

# Closes the message producer.
#
# + return - `jms:Error` if there is an error or else nil
isolated remote function close() returns Error? = @java:Method {
'class: "io.ballerina.stdlib.java.jms.JmsProducer"
} external;
};

isolated function getJmsMessage(Session session, Message message) returns handle|Error {
Expand Down
24 changes: 24 additions & 0 deletions native/src/main/java/io/ballerina/stdlib/java.jms/JmsProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,28 @@ public static Object sendTo(BObject producer, BObject session, BMap<BString, Obj
}
return null;
}

/**
* Closes the message producer.
*
* @param producer Ballerina producer object
* @return A Ballerina `jms:Error` if the JMS provider fails to close the producer due to some internal error.
*/
public static Object close(BObject producer) {
Object nativeProducer = producer.getNativeData(NATIVE_PRODUCER);
if (Objects.isNull(nativeProducer)) {
return ErrorCreator.createError(ModuleUtils.getModule(), JMS_ERROR,
StringUtils.fromString("Could not find the native JMS MessageProducer"),
null, null);
}
try {
((MessageProducer) nativeProducer).close();
} catch (JMSException exception) {
BError cause = ErrorCreator.createError(exception);
return ErrorCreator.createError(ModuleUtils.getModule(), JMS_ERROR,
StringUtils.fromString(String.format("Error occurred while closing the message produce: %s",
exception.getMessage())), cause, null);
}
return null;
}
}

0 comments on commit 359586a

Please sign in to comment.