ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.58k stars 737 forks source link

JMS connector should return error if connection creation to the broker is failed #16589

Closed abeykoon closed 5 years ago

abeykoon commented 5 years ago

Description:

Consider following code.

function initializeConsumer(MessageStoreConfiguration storeConfig) returns
 (jms:Connection, jms:Session, jms:QueueReceiver) | error {

    string initialContextFactory = getInitialContextFactory(storeConfig.messageBroker);
    string acknowledgementMode = "CLIENT_ACKNOWLEDGE";
    string queueName = storeConfig.queueName;

    // This initializes a JMS connection with the provider.
    jms:Connection jmsConnection = new({
        initialContextFactory: initialContextFactory,
        providerUrl: storeConfig.providerUrl});

    // This initializes a JMS session on top of the created connection.
    jms:Session jmsSession = new(jmsConnection, {
            acknowledgementMode: acknowledgementMode
        });

    // This initializes a queue receiver.
    jms:QueueReceiver queueReceiver = new(jmsSession, queueName = queueName);

    (jms:Connection, jms:Session, jms:QueueReceiver) brokerConnection = (jmsConnection, jmsSession, queueReceiver);

    return brokerConnection;
}

Following does not return a ballerina error when broker is down.

    jms:Connection jmsConnection = new({
        initialContextFactory: initialContextFactory,
        providerUrl: storeConfig.providerUrl});

Instead it panics and caller need to trap the error. IMO, the API should return an error if connection is refused to the broker.

Steps to reproduce: N/A Affected Versions:

0.991.0

abeykoon commented 5 years ago

Same goes with session and queueReceiver as well.

daneshk commented 5 years ago

Closing this issue. Since we moved JMS module to https://github.com/wso2-ballerina/module-jms repository. Please refer wso2-ballerina/module-jms#16 to get latest updates of this issue