-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from ayeshLK/master
Add examples to the Ballerina IBM MQ connector
- Loading branch information
Showing
8 changed files
with
154 additions
and
0 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
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 |
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,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"])); | ||
} | ||
} | ||
} | ||
} |
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,8 @@ | ||
[package] | ||
org = "wso2" | ||
name = "ibmmq_client_security" | ||
version = "0.1.0" | ||
distribution = "2201.8.2" | ||
|
||
[build-options] | ||
observabilityIncluded = true |
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,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.
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,8 @@ | ||
[package] | ||
org = "wso2" | ||
name = "send_mqrfh2_headers" | ||
version = "0.1.0" | ||
distribution = "2201.8.2" | ||
|
||
[build-options] | ||
observabilityIncluded = true |
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,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(); | ||
} |