Skip to content

Commit

Permalink
Merge pull request ballerina-platform#5 from ballerina-platform/conne…
Browse files Browse the repository at this point in the history
…ctor-implementation

Add IBM MQ connector functionality
  • Loading branch information
ayeshLK authored Oct 31, 2023
2 parents b511c2d + 84aad43 commit cf54a8f
Show file tree
Hide file tree
Showing 15 changed files with 865 additions and 72 deletions.
25 changes: 24 additions & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,35 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
]

[[package]]
org = "ballerinax"
name = "ibm.ibmmq"
version = "0.1.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "test"}
]
modules = [
{org = "ballerinax", packageName = "ibm.ibmmq", moduleName = "ibm.ibmmq"}
Expand Down
94 changes: 47 additions & 47 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,51 +102,51 @@ task commitTomlFiles {
}
}

// task startActiveMQServer() {
// doLast {
// if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
// def stdOut = new ByteArrayOutputStream()
// exec {
// commandLine 'sh', '-c', "docker ps --filter name=activemq-test"
// standardOutput = stdOut
// }
// if (!stdOut.toString().contains("activemq-test")) {
// println "Starting ActiveMQ server."
// exec {
// commandLine 'sh', '-c', "docker-compose -f tests/resources/docker-compose.yaml up -d"
// standardOutput = stdOut
// }
// println stdOut.toString()
// sleep(5 * 1000)
// } else {
// println "ActiveMQ server is already running."
// }
// }
// }
// }

// task stopActiveMQServer() {
// doLast {
// if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
// def stdOut = new ByteArrayOutputStream()
// exec {
// commandLine 'sh', '-c', "docker ps --filter name=activemq-test"
// standardOutput = stdOut
// }
// if (stdOut.toString().contains("activemq-test")) {
// println "Stopping ActiveMQ server."
// exec {
// commandLine 'sh', '-c', "docker-compose -f tests/resources/docker-compose.yaml rm -svf"
// standardOutput = stdOut
// }
// println stdOut.toString()
// sleep(5 * 1000)
// } else {
// println "ActiveMQ server is not started."
// }
// }
// }
// }
task startIBMMQServer() {
doLast {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
def stdOut = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', "docker ps --filter name=ibmmq-test"
standardOutput = stdOut
}
if (!stdOut.toString().contains("ibmmq-test")) {
println "Starting IBMMQ server."
exec {
commandLine 'sh', '-c', "docker-compose -f tests/resources/docker-compose.yaml up -d"
standardOutput = stdOut
}
println stdOut.toString()
sleep(5 * 1000)
} else {
println "IBMMQ server is already running."
}
}
}
}

task stopIBMMQServer() {
doLast {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
def stdOut = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', "docker ps --filter name=ibmmq-test"
standardOutput = stdOut
}
if (stdOut.toString().contains("ibmmq-test")) {
println "Stopping IBMMQ server."
exec {
commandLine 'sh', '-c', "docker-compose -f tests/resources/docker-compose.yaml rm -svf"
standardOutput = stdOut
}
println stdOut.toString()
sleep(5 * 1000)
} else {
println "IBMMQ server is not started."
}
}
}
}

publishing {
publications {
Expand All @@ -168,8 +168,8 @@ publishing {

updateTomlFiles.dependsOn copyStdlibs

// test.dependsOn startActiveMQServer
// build.finalizedBy stopActiveMQServer
test.dependsOn startIBMMQServer
build.finalizedBy stopIBMMQServer

build.dependsOn ":ibm.ibmmq-native:build"
build.dependsOn "generatePomFileForMavenPublication"
Expand Down
51 changes: 51 additions & 0 deletions ballerina/constants.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.

// Option to indicate whether the topic is being opened for either publication or subscription.
public const OPEN_AS_SUBSCRIPTION = 1;
public const OPEN_AS_PUBLICATION = 2;

// Options that control the opening of the queue for a consumer.
public const MQOO_BROWSE = 8;
public const MQOO_INPUT_AS_Q_DEF = 1;
public const MQOO_INPUT_EXCLUSIVE = 4;
public const MQOO_INPUT_SHARED = 2;

// Options that control the opening of the topic for either publication or subscription.
public const MQOO_ALTERNATE_USER_AUTHORITY = 4096;
public const MQOO_BIND_AS_Q_DEF = 0;
public const MQOO_FAIL_IF_QUIESCING = 8192;
public const MQOO_OUTPUT = 16;
public const MQOO_PASS_ALL_CONTEXT = 512;
public const MQOO_PASS_IDENTITY_CONTEXT = 256;
public const MQOO_SET_ALL_CONTEXT = 2048;
public const MQOO_SET_IDENTITY_CONTEXT = 1024;
public const MQSO_CREATE = 2;

// Options related to the the get message in a topic.
public const MQGMO_WAIT = 1;
public const MQGMO_NO_WAIT = 0;
public const MQGMO_SYNCPOINT = 2;
public const MQGMO_NO_SYNCPOINT = 4;
public const MQGMO_BROWSE_FIRST = 16;
public const MQGMO_BROWSE_NEXT = 32;
public const MQGMO_BROWSE_MSG_UNDER_CURSOR = 2048;
public const MQGMO_MSG_UNDER_CURSOR = 256;
public const MQGMO_LOCK = 512;
public const MQGMO_UNLOCK = 1024;
public const MQGMO_ACCEPT_TRUNCATED_MSG = 64;
public const MQGMO_FAIL_IF_QUIESCING = 8192;
public const MQGMO_CONVERT = 16384;
42 changes: 38 additions & 4 deletions ballerina/destination.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,50 @@
// specific language governing permissions and limitations
// under the License.

import ballerina/jballerina.java;

public type Destination distinct client object {
remote function put(Message message) returns Error?;

remote function get() returns Message|Error?;
remote function get(*GetMessageOptions getMessageOptions) returns Message|Error?;

remote function close() returns Error?;
};

public type Queue distinct client object {
public isolated client class Queue {
*Destination;
};

public type Topic distinct client object {
remote function put(Message message) returns Error? =
@java:Method {
'class: "io.ballerina.lib.ibm.ibmmq.Queue"
} external;

remote function get(*GetMessageOptions getMessageOptions) returns Message|Error? =
@java:Method {
'class: "io.ballerina.lib.ibm.ibmmq.Queue"
} external;

remote function close() returns Error? =
@java:Method {
'class: "io.ballerina.lib.ibm.ibmmq.Queue"
} external;
}

public isolated client class Topic {
*Destination;

remote function put(Message message) returns Error? =
@java:Method {
'class: "io.ballerina.lib.ibm.ibmmq.Topic"
} external;

remote function get(*GetMessageOptions getMessageOptions) returns Message|Error? =
@java:Method {
'class: "io.ballerina.lib.ibm.ibmmq.Topic"
} external;

remote function close() returns Error? =
@java:Method {
'class: "io.ballerina.lib.ibm.ibmmq.Topic"
} external;
};
13 changes: 12 additions & 1 deletion ballerina/errors.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
// specific language governing permissions and limitations
// under the License.

public type Error distinct error;
public type Error distinct error<ErrorDetails>;

# The error details type for the module.
#
# + reasonCode - The reason code for the error
# + errorCode - The error code for the error
# + completionCode - The completion code for the error
public type ErrorDetails record {|
int reasonCode?;
string errorCode?;
int completionCode?;
|};
20 changes: 14 additions & 6 deletions ballerina/queue_manager.bal
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ public isolated class QueueManager {
'class: "io.ballerina.lib.ibm.ibmmq.QueueManager"
} external;

public isolated function accessQueue(string queueName, ConnectionOpenOptions options) returns Queue|Error {
return error Error("Not implemented");
}
public isolated function accessQueue(string queueName, int options) returns Queue|Error =
@java:Method {
'class: "io.ballerina.lib.ibm.ibmmq.QueueManager"
} external;

public isolated function accessTopic(string topicName, string topicString, ConnectionOpenOptions options) returns Topic|Error {
return error Error("Not implemented");
}
public isolated function accessTopic(string topicName, string topicString, OPEN_TOPIC_OPTION openTopicOption,
int options) returns Topic|Error =
@java:Method {
'class: "io.ballerina.lib.ibm.ibmmq.QueueManager"
} external;

public isolated function disconnect() returns Error? =
@java:Method {
'class: "io.ballerina.lib.ibm.ibmmq.QueueManager"
} external;
}
Loading

0 comments on commit cf54a8f

Please sign in to comment.