Skip to content

Commit

Permalink
Merge pull request #25 from ayeshLK/master
Browse files Browse the repository at this point in the history
Add examples to the Ballerina IBM MQ connector
  • Loading branch information
ayeshLK committed Nov 14, 2023
2 parents c3c5a7a + 72c88f3 commit af25424
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/consume-mqrfh2-headers/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
org = "wso2"
name = "consume_mqrfh2_headers"
version = "0.1.0"
distribution = "2201.8.2"

[build-options]
observabilityIncluded = true
44 changes: 44 additions & 0 deletions examples/consume-mqrfh2-headers/main.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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:MQRFH2 {
table<ibmmq:MQRFH2Field> key(folder, 'field) fieldTable = header.fieldValues;
if fieldTable.hasKey(["mcd", "Msd"]) {
io:println(fieldTable.get(["mcd", "Msd"]));
}
}
}
}
8 changes: 8 additions & 0 deletions examples/ibmmq-client-security/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
org = "wso2"
name = "ibmmq_client_security"
version = "0.1.0"
distribution = "2201.8.2"

[build-options]
observabilityIncluded = true
46 changes: 46 additions & 0 deletions examples/ibmmq-client-security/main.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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",
port = 1415,
channel = "DEV.APP.SVRCONN",
// Provide the relevant SSL cipher-suite.
sslCipherSuite = ibmmq:TLS12ORHIGHER,
secureSocket = {
// Provide the client truststrore here.
cert: {
path: "./resources/clientTrustStore.p12",
password: "password"
},
// Provide the client keystore here.
'key: {
path: "./resources/clientKeyStore.p12",
password: "password"
}
}
);
ibmmq:Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", ibmmq:MQOO_OUTPUT);
check producer->put({
payload: "This is a sample message to IBM MQ queue".toBytes()
});
check producer->close();
check queueManager.disconnect();
}
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions examples/send-mqrfh2-headers/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
org = "wso2"
name = "send_mqrfh2_headers"
version = "0.1.0"
distribution = "2201.8.2"

[build-options]
observabilityIncluded = true
40 changes: 40 additions & 0 deletions examples/send-mqrfh2-headers/main.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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:MQRFH2 mqrfh2Header = {
flags: 12,
fieldValues: table [
{folder: "mcd", 'field: "Msd", value: "TestMcdValue"},
{folder: "jms", 'field: "Dlv", value: 134},
{folder: "mqps", 'field: "Ret", value: true}
]
};

check producer->put({
headers: [mqrfh2Header],
payload: "This is a sample message to IBM MQ queue".toBytes()
});
check producer->close();
check queueManager.disconnect();
}

0 comments on commit af25424

Please sign in to comment.