Skip to content

Commit

Permalink
Merge pull request #9 from ayeshLK/destination-api-upgrade
Browse files Browse the repository at this point in the history
Refactor IBM MQ destination API
  • Loading branch information
ayeshLK authored Oct 30, 2023
2 parents 509aa08 + ae193a6 commit 1305cf4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public type AccessTopicOptions MQOO_ALTERNATE_USER_AUTHORITY|MQOO_BIND_AS_Q_DEF|

public type GetMessageOptions record {|
GM_OPTIONS gmOptions = MQGMO_NO_WAIT;
int waitInterval = 0;
int waitInterval = 10;
|};

public type Property record {|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static MQGetMessageOptions getGetMessageOptions(BMap<BString, Object> bOp
int waitInterval = bOptions.getIntValue(WAIT_INTERVAL).intValue();
int options = bOptions.getIntValue(OPTIONS).intValue();
MQGetMessageOptions getMessageOptions = new MQGetMessageOptions();
getMessageOptions.waitInterval = waitInterval;
getMessageOptions.waitInterval = waitInterval * 1000;
getMessageOptions.options = options;
return getMessageOptions;
}
Expand Down
16 changes: 11 additions & 5 deletions native/src/main/java/io/ballerina/lib/ibm.ibmmq/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQQueue;
import com.ibm.mq.constants.CMQC;
import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.Future;
import io.ballerina.runtime.api.values.BError;
Expand Down Expand Up @@ -50,7 +51,7 @@ public static Object put(Environment environment, BObject queueObject, BMap<BStr
try {
queue.put(mqMessage);
future.complete(null);
} catch (Exception e) {
} catch (MQException e) {
BError bError = createError(IBMMQ_ERROR,
String.format("Error occurred while putting a message to the queue: %s", e.getMessage()), e);
future.complete(bError);
Expand All @@ -68,10 +69,15 @@ public static Object get(Environment environment, BObject queueObject, BMap<BStr
MQMessage message = new MQMessage();
queue.get(message, getMessageOptions);
future.complete(CommonUtils.getBMessageFromMQMessage(message));
} catch (Exception e) {
BError bError = createError(IBMMQ_ERROR,
String.format("Error occurred while getting a message from the queue: %s", e.getMessage()), e);
future.complete(bError);
} catch (MQException e) {
if (e.reasonCode == CMQC.MQRC_NO_MSG_AVAILABLE) {
future.complete(null);
} else {
BError bError = createError(IBMMQ_ERROR,
String.format("Error occurred while getting a message from the queue: %s",
e.getMessage()), e);
future.complete(bError);
}
}
});
return null;
Expand Down

0 comments on commit 1305cf4

Please sign in to comment.