diff --git a/examples/consume-mqiih-headers/Ballerina.toml b/examples/consume-mqiih-headers/Ballerina.toml new file mode 100644 index 0000000..53ff3ad --- /dev/null +++ b/examples/consume-mqiih-headers/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "consume_mqcih_headers" +version = "0.1.0" +distribution = "2201.8.2" + +[build-options] +observabilityIncluded = true diff --git a/examples/consume-mqiih-headers/main.bal b/examples/consume-mqiih-headers/main.bal new file mode 100644 index 0000000..2dc8482 --- /dev/null +++ b/examples/consume-mqiih-headers/main.bal @@ -0,0 +1,42 @@ +// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// 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. + +import ballerinax/ibm.ibmmq; +import ballerina/io; + +public function main() returns error? { + ibmmq:QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN" + ); + ibmmq:Queue consumer = check queueManager.accessQueue( + "DEV.QUEUE.1", ibmmq:MQOO_INPUT_AS_Q_DEF); + while true { + ibmmq:Message? message = check consumer->get(options = ibmmq:MQGMO_WAIT); + if message is () { + continue; + } + io:println(string:fromBytes(message.payload)); + ibmmq:Header[]? headers = message.headers; + if headers is () { + continue; + } + ibmmq:Header header = headers[0]; + if header is ibmmq:MQIIH { + io:println(header.lTermOverride); + io:println(header.mfsMapName); + } + } +} diff --git a/examples/send-mqiih-headers/Ballerina.toml b/examples/send-mqiih-headers/Ballerina.toml new file mode 100644 index 0000000..eda5bc5 --- /dev/null +++ b/examples/send-mqiih-headers/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "send_mq_headers" +version = "0.1.0" +distribution = "2201.8.2" + +[build-options] +observabilityIncluded = true diff --git a/examples/send-mqiih-headers/main.bal b/examples/send-mqiih-headers/main.bal new file mode 100644 index 0000000..606b153 --- /dev/null +++ b/examples/send-mqiih-headers/main.bal @@ -0,0 +1,43 @@ +// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// 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. + +import ballerinax/ibm.ibmmq; + +public function main() returns error? { + ibmmq:QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN" + ); + ibmmq:Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", ibmmq:MQOO_OUTPUT); + + ibmmq:MQIIH mqiihHeader = { + flags: 12, + lTermOverride: "ltorride", + mfsMapName: "mfsmapnm", + replyToFormat: "reformat", + authenticator: "authenti", + tranInstanceId: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + tranState: "t", + commitMode: "c", + securityScope: "s" + }; + + check producer->put({ + headers: [mqiihHeader], + payload: "This is a sample message to IBM MQ queue".toBytes() + }); + check producer->close(); + check queueManager.disconnect(); +}