Skip to content

Commit

Permalink
Merge pull request #38 from ayeshLK/main
Browse files Browse the repository at this point in the history
Restructure `ibm.ibmmq` examples
  • Loading branch information
ayeshLK authored Feb 26, 2024
2 parents 2724d3c + 37df1ac commit bcd7f6e
Show file tree
Hide file tree
Showing 33 changed files with 453 additions and 28 deletions.
1 change: 1 addition & 0 deletions examples/consume-messages/.github/README.md
5 changes: 5 additions & 0 deletions examples/consume-messages/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
org = "wso2"
name = "consume_messages"
version = "0.1.0"
distribution = "2201.8.4"
7 changes: 7 additions & 0 deletions examples/consume-messages/Config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
queueManagerName = "QM1"
host = "localhost"
port = 1414
channel = "DEV.APP.SVRCONN"
userID = "app"
password = "password"
queueName = "DEV.QUEUE.1"
31 changes: 31 additions & 0 deletions examples/consume-messages/Consume Messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Consume messages

This example demonstrates how to consume messages from an IBM MQ queue.

## Prerequisites

### 1. Setup IBM MQ server

Refer to the [Setup Guide](https://dev-central.ballerina.io/ballerinax/ibm.ibmmq/latest#setup-guide) to set up the IBM MQ server locally.

### 2. Configuration

Update IBM MQ related configurations in `Config.toml` in the example directory:

```toml
queueManagerName = "<queue-manager-name>"
host = "<host>"
port = <port>
channel = "<ibm-mq-channel>"
userID = "<user-ID>"
password = "<password>"
queueName = "<queue-name>"
```

## Run the Example

Execute the following command to run the example:

```bash
bal run
```
44 changes: 44 additions & 0 deletions examples/consume-messages/main.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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.

import ballerinax/ibm.ibmmq;
import ballerina/io;

configurable string queueManagerName = ?;
configurable string host = ?;
configurable int port = ?;
configurable string channel = ?;
configurable string userID = ?;
configurable string password = ?;
configurable string queueName = ?;

public function main() returns error? {
ibmmq:QueueManager queueManager = check new (
name = queueManagerName,
host = host,
channel = channel,
userID = userID,
password = password
);
ibmmq:Queue queue = check queueManager.accessQueue(queueName, ibmmq:MQOO_INPUT_AS_Q_DEF);
ibmmq:Message? message = check queue->get(options = ibmmq:MQGMO_WAIT);
while true {
if message is () {
continue;
}
io:println(string:fromBytes(message.payload));
}
}
1 change: 1 addition & 0 deletions examples/consume-mqiih-headers/.github/README.md
2 changes: 1 addition & 1 deletion examples/consume-mqiih-headers/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
org = "wso2"
name = "consume_mqcih_headers"
name = "consume_mqiih_headers"
version = "0.1.0"
distribution = "2201.8.2"

Expand Down
7 changes: 7 additions & 0 deletions examples/consume-mqiih-headers/Config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
queueManagerName = "QM1"
host = "localhost"
port = 1414
channel = "DEV.APP.SVRCONN"
userID = "app"
password = "password"
queueName = "DEV.QUEUE.1"
31 changes: 31 additions & 0 deletions examples/consume-mqiih-headers/Consume MQIIH Headers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Consume MQIIH headers

This example demonstrates how to consume messages with MQIIH header from an IBM MQ queue.

## Prerequisites

### 1. Setup IBM MQ server

Refer to the [Setup Guide](https://dev-central.ballerina.io/ballerinax/ibm.ibmmq/latest#setup-guide) to set up the IBM MQ server locally.

### 2. Configuration

Update IBM MQ related configurations in `Config.toml` in the example directory:

```toml
queueManagerName = "<queue-manager-name>"
host = "<host>"
port = <port>
channel = "<ibm-mq-channel>"
userID = "<user-ID>"
password = "<password>"
queueName = "<queue-name>"
```

## Run the Example

Execute the following command to run the example:

```bash
bal run
```
20 changes: 16 additions & 4 deletions examples/consume-mqiih-headers/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@
import ballerinax/ibm.ibmmq;
import ballerina/io;

configurable string queueManagerName = ?;
configurable string host = ?;
configurable int port = ?;
configurable string channel = ?;
configurable string userID = ?;
configurable string password = ?;
configurable string queueName = ?;

public function main() returns error? {
ibmmq:QueueManager queueManager = check new (
name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"
name = queueManagerName,
host = host,
channel = channel,
userID = userID,
password = password
);
ibmmq:Queue consumer = check queueManager.accessQueue(
"DEV.QUEUE.1", ibmmq:MQOO_INPUT_AS_Q_DEF);
ibmmq:Queue queue = check queueManager.accessQueue(queueName, ibmmq:MQOO_INPUT_AS_Q_DEF);

while true {
ibmmq:Message? message = check consumer->get(options = ibmmq:MQGMO_WAIT);
ibmmq:Message? message = check queue->get(options = ibmmq:MQGMO_WAIT);
if message is () {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions examples/consume-mqrfh2-headers/.github/README.md
7 changes: 7 additions & 0 deletions examples/consume-mqrfh2-headers/Config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
queueManagerName = "QM1"
host = "localhost"
port = 1414
channel = "DEV.APP.SVRCONN"
userID = "app"
password = "password"
queueName = "DEV.QUEUE.1"
31 changes: 31 additions & 0 deletions examples/consume-mqrfh2-headers/Consume MQRFH2 Headers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Consume MQRFH2 headers

This example demonstrates how to consume messages with MQRFH2 header from an IBM MQ queue.

## Prerequisites

### 1. Setup IBM MQ server

Refer to the [Setup Guide](https://dev-central.ballerina.io/ballerinax/ibm.ibmmq/latest#setup-guide) to set up the IBM MQ server locally.

### 2. Configuration

Update IBM MQ related configurations in `Config.toml` in the example directory:

```toml
queueManagerName = "<queue-manager-name>"
host = "<host>"
port = <port>
channel = "<ibm-mq-channel>"
userID = "<user-ID>"
password = "<password>"
queueName = "<queue-name>"
```

## Run the Example

Execute the following command to run the example:

```bash
bal run
```
20 changes: 16 additions & 4 deletions examples/consume-mqrfh2-headers/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@
import ballerinax/ibm.ibmmq;
import ballerina/io;

configurable string queueManagerName = ?;
configurable string host = ?;
configurable int port = ?;
configurable string channel = ?;
configurable string userID = ?;
configurable string password = ?;
configurable string queueName = ?;

public function main() returns error? {
ibmmq:QueueManager queueManager = check new (
name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"
name = queueManagerName,
host = host,
channel = channel,
userID = userID,
password = password
);
ibmmq:Queue consumer = check queueManager.accessQueue(
"DEV.QUEUE.1", ibmmq:MQOO_INPUT_AS_Q_DEF);
ibmmq:Queue queue = check queueManager.accessQueue(queueName, ibmmq:MQOO_INPUT_AS_Q_DEF);

while true {
ibmmq:Message? message = check consumer->get(options = ibmmq:MQGMO_WAIT);
ibmmq:Message? message = check queue->get(options = ibmmq:MQGMO_WAIT);
if message is () {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions examples/ibmmq-client-security/.github/README.md
7 changes: 7 additions & 0 deletions examples/ibmmq-client-security/Config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
queueManagerName = "QM1"
host = "localhost"
port = 1414
channel = "DEV.APP.SVRCONN"
userID = "app"
password = "password"
queueName = "DEV.QUEUE.1"
31 changes: 31 additions & 0 deletions examples/ibmmq-client-security/Securing IBM MQ Client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Securing IBM MQ client

This example demonstrates how to initiate secure communication between an IBM MQ client and an IBM MQ server.

## Prerequisites

### 1. Setup IBM MQ server

Refer to the [Setup Guide](https://dev-central.ballerina.io/ballerinax/ibm.ibmmq/latest#setup-guide) to set up the IBM MQ server locally.

### 2. Configuration

Update IBM MQ related configurations in `Config.toml` in the example directory:

```toml
queueManagerName = "<queue-manager-name>"
host = "<host>"
port = <port>
channel = "<ibm-mq-channel>"
userID = "<user-ID>"
password = "<password>"
queueName = "<queue-name>"
```

## Run the Example

Execute the following command to run the example:

```bash
bal run
```
23 changes: 16 additions & 7 deletions examples/ibmmq-client-security/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@

import ballerinax/ibm.ibmmq;

configurable string queueManagerName = ?;
configurable string host = ?;
configurable int port = ?;
configurable string channel = ?;
configurable string userID = ?;
configurable string password = ?;
configurable string queueName = ?;

public function main() returns error? {
ibmmq:QueueManager queueManager = check new (
name = "QM1",
host = "localhost",
port = 1415,
channel = "DEV.APP.SVRCONN",
name = queueManagerName,
host = host,
channel = channel,
userID = userID,
password = password,
// Provide the relevant SSL cipher-suite.
sslCipherSuite = ibmmq:TLS12ORHIGHER,
secureSocket = {
Expand All @@ -37,10 +46,10 @@ public function main() returns error? {
}
}
);
ibmmq:Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", ibmmq:MQOO_OUTPUT);
check producer->put({
ibmmq:Queue queue = check queueManager.accessQueue(queueName, ibmmq:MQOO_OUTPUT);
check queue->put({
payload: "This is a sample message to IBM MQ queue".toBytes()
});
check producer->close();
check queue->close();
check queueManager.disconnect();
}
1 change: 1 addition & 0 deletions examples/produce-messages/.github/README.md
5 changes: 5 additions & 0 deletions examples/produce-messages/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
org = "wso2"
name = "produce_messages"
version = "0.1.0"
distribution = "2201.8.4"
7 changes: 7 additions & 0 deletions examples/produce-messages/Config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
queueManagerName = "QM1"
host = "localhost"
port = 1414
channel = "DEV.APP.SVRCONN"
userID = "app"
password = "password"
queueName = "DEV.QUEUE.1"
31 changes: 31 additions & 0 deletions examples/produce-messages/Produce Messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Produce messages

This example demonstrates how to produce messages to an IBM MQ queue.

## Prerequisites

### 1. Setup IBM MQ server

Refer to the [Setup Guide](https://dev-central.ballerina.io/ballerinax/ibm.ibmmq/latest#setup-guide) to set up the IBM MQ server locally.

### 2. Configuration

Update IBM MQ related configurations in `Config.toml` in the example directory:

```toml
queueManagerName = "<queue-manager-name>"
host = "<host>"
port = <port>
channel = "<ibm-mq-channel>"
userID = "<user-ID>"
password = "<password>"
queueName = "<queue-name>"
```

## Run the Example

Execute the following command to run the example:

```bash
bal run
```
Loading

0 comments on commit bcd7f6e

Please sign in to comment.