forked from ballerina-platform/module-ballerinax-ibm.ibmmq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to retrieve messages based on msg-id or correlation-id
- Loading branch information
Showing
6 changed files
with
151 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
native/src/main/java/io/ballerina/lib/ibm.ibmmq/config/GetMessageOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.lib.ibm.ibmmq.config; | ||
|
||
import io.ballerina.runtime.api.values.BMap; | ||
import io.ballerina.runtime.api.values.BString; | ||
|
||
import static io.ballerina.lib.ibm.ibmmq.Constants.MATCH_OPTIONS; | ||
import static io.ballerina.lib.ibm.ibmmq.Constants.OPTIONS; | ||
import static io.ballerina.lib.ibm.ibmmq.Constants.WAIT_INTERVAL; | ||
|
||
/** | ||
* Represents the IBM MQ GET message options. | ||
* | ||
* @param options Get message option | ||
* @param waitInterval The maximum time (in seconds) that a `get` call waits for a suitable message to arrive. | ||
* It is used in conjunction with `MQGMO_WAIT`. | ||
* @param matchOptions Message selection criteria | ||
*/ | ||
public record GetMessageOptions(int options, int waitInterval, MatchOptions matchOptions) { | ||
|
||
public GetMessageOptions(BMap<BString, Object> getMsgOptions) { | ||
this ( | ||
getMsgOptions.getIntValue(OPTIONS).intValue(), | ||
getMsgOptions.getIntValue(WAIT_INTERVAL).intValue() * 1000, | ||
getMatchOptions(getMsgOptions) | ||
); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static MatchOptions getMatchOptions(BMap<BString, Object> getMsgOptions) { | ||
if (!getMsgOptions.containsKey(MATCH_OPTIONS)) { | ||
return null; | ||
} | ||
return new MatchOptions((BMap<BString, Object>) getMsgOptions.getMapValue(MATCH_OPTIONS)); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
native/src/main/java/io/ballerina/lib/ibm.ibmmq/config/MatchOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.lib.ibm.ibmmq.config; | ||
|
||
import io.ballerina.runtime.api.values.BMap; | ||
import io.ballerina.runtime.api.values.BString; | ||
|
||
import static io.ballerina.lib.ibm.ibmmq.Constants.CORRELATION_ID_FIELD; | ||
import static io.ballerina.lib.ibm.ibmmq.Constants.MESSAGE_ID_FIELD; | ||
|
||
/** | ||
* Represents the selection criteria that determine which message is retrieved. | ||
* | ||
* @param messageId The message identifier of the message which needs to be retrieved | ||
* @param correlationId The Correlation identifier of the message which needs to be retrieved | ||
*/ | ||
public record MatchOptions(byte[] messageId, byte[] correlationId) { | ||
|
||
public MatchOptions(BMap<BString, Object> matchOptions) { | ||
this ( | ||
getValueIfPresent(matchOptions, MESSAGE_ID_FIELD), | ||
getValueIfPresent(matchOptions, CORRELATION_ID_FIELD) | ||
); | ||
} | ||
|
||
private static byte[] getValueIfPresent(BMap<BString, Object> matchOptions, BString key) { | ||
if (!matchOptions.containsKey(key)) { | ||
return null; | ||
} | ||
return matchOptions.getArrayValue(key).getByteArray(); | ||
} | ||
} |