Skip to content

Commit

Permalink
Merge pull request #28 from dilanSachi/add-examples
Browse files Browse the repository at this point in the history
Add MQIIH header samples
  • Loading branch information
dilanSachi committed Nov 15, 2023
2 parents c706df7 + fedf8a5 commit 5fdf426
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/consume-mqiih-headers/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
org = "wso2"
name = "consume_mqcih_headers"
version = "0.1.0"
distribution = "2201.8.2"

[build-options]
observabilityIncluded = true
42 changes: 42 additions & 0 deletions examples/consume-mqiih-headers/main.bal
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
8 changes: 8 additions & 0 deletions examples/send-mqiih-headers/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
org = "wso2"
name = "send_mq_headers"
version = "0.1.0"
distribution = "2201.8.2"

[build-options]
observabilityIncluded = true
43 changes: 43 additions & 0 deletions examples/send-mqiih-headers/main.bal
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 5fdf426

Please sign in to comment.