Example usage for javax.jms Session DUPS_OK_ACKNOWLEDGE

List of usage examples for javax.jms Session DUPS_OK_ACKNOWLEDGE

Introduction

In this page you can find the example usage for javax.jms Session DUPS_OK_ACKNOWLEDGE.

Prototype

int DUPS_OK_ACKNOWLEDGE

To view the source code for javax.jms Session DUPS_OK_ACKNOWLEDGE.

Click Source Link

Document

This acknowledgment mode instructs the session to lazily acknowledge the delivery of messages.

Usage

From source file:nl.nn.adapterframework.jms.JMSFacade.java

/**
 * String-version of {@link #setAckMode(int)}
 *//*from   w  w w .  ja  v  a  2  s .c o m*/
public void setAcknowledgeMode(String acknowledgeMode) {

    if (acknowledgeMode.equalsIgnoreCase("auto") || acknowledgeMode.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) {
        ackMode = Session.AUTO_ACKNOWLEDGE;
    } else if (acknowledgeMode.equalsIgnoreCase("dups")
            || acknowledgeMode.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) {
        ackMode = Session.DUPS_OK_ACKNOWLEDGE;
    } else if (acknowledgeMode.equalsIgnoreCase("client")
            || acknowledgeMode.equalsIgnoreCase("CLIENT_ACKNOWLEDGE")) {
        ackMode = Session.CLIENT_ACKNOWLEDGE;
    } else {
        // ignore all ack modes, to test no acking
        log.warn("[" + name + "] invalid acknowledgemode:[" + acknowledgeMode + "] setting no acknowledge");
        ackMode = -1;
    }

}

From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.factory.JMSConnectionFactory.java

public JMSConnectionFactory(Properties properties) {
    try {// w  ww  .j a va 2  s . c  o  m
        ctx = new InitialContext(properties);
    } catch (NamingException e) {
        logger.error("NamingException while obtaining initial context. " + e.getMessage(), e);
    }

    String connectionFactoryType = properties.getProperty(JMSConstants.CONNECTION_FACTORY_TYPE);
    if ("topic".equals(connectionFactoryType)) {
        this.destinationType = JMSConstants.JMSDestinationType.TOPIC;
    } else {
        this.destinationType = JMSConstants.JMSDestinationType.QUEUE;
    }

    if (properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER) == null || JMSConstants.JMS_SPEC_VERSION_1_1
            .equals(properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER))) {
        jmsSpec = JMSConstants.JMS_SPEC_VERSION_1_1;
    } else if (JMSConstants.JMS_SPEC_VERSION_2_0
            .equals(properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER))) {
        jmsSpec = JMSConstants.JMS_SPEC_VERSION_2_0;
    } else {
        jmsSpec = JMSConstants.JMS_SPEC_VERSION_1_0;
    }

    if ("true".equalsIgnoreCase(properties.getProperty(JMSConstants.PARAM_IS_SHARED_SUBSCRIPTION))) {
        isSharedSubscription = true;
    } else {
        isSharedSubscription = false;
    }

    noPubSubLocal = Boolean.valueOf(properties.getProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL));

    clientId = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID);
    subscriptionName = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_NAME);

    if (isSharedSubscription) {
        if (subscriptionName == null) {
            logger.info("Subscription name is not given. Therefor declaring a non-shared subscription");
            isSharedSubscription = false;
        }
    }

    String subDurable = properties.getProperty(JMSConstants.PARAM_SUB_DURABLE);
    if (subDurable != null) {
        isDurable = Boolean.parseBoolean(subDurable);
    }
    String msgSelector = properties.getProperty(JMSConstants.PARAM_MSG_SELECTOR);
    if (msgSelector != null) {
        messageSelector = msgSelector;
    }
    this.connectionFactoryString = properties.getProperty(JMSConstants.CONNECTION_FACTORY_JNDI_NAME);
    if (connectionFactoryString == null || "".equals(connectionFactoryString)) {
        connectionFactoryString = "QueueConnectionFactory";
    }

    this.destinationName = properties.getProperty(JMSConstants.DESTINATION_NAME);
    if (destinationName == null || "".equals(destinationName)) {
        destinationName = "QUEUE_" + System.currentTimeMillis();
    }

    String strTransactedSession = properties.getProperty(JMSConstants.SESSION_TRANSACTED);
    if (strTransactedSession == null || "".equals(strTransactedSession)
            || !strTransactedSession.equals("true")) {
        transactedSession = false;
    } else if ("true".equals(strTransactedSession)) {
        transactedSession = true;
    }

    String strSessionAck = properties.getProperty(JMSConstants.SESSION_ACK);
    if (null == strSessionAck) {
        sessionAckMode = 1;
    } else if (strSessionAck.equals("AUTO_ACKNOWLEDGE")) {
        sessionAckMode = Session.AUTO_ACKNOWLEDGE;
    } else if (strSessionAck.equals("CLIENT_ACKNOWLEDGE")) {
        sessionAckMode = Session.CLIENT_ACKNOWLEDGE;
    } else if (strSessionAck.equals("DUPS_OK_ACKNOWLEDGE")) {
        sessionAckMode = Session.DUPS_OK_ACKNOWLEDGE;
    } else if (strSessionAck.equals("SESSION_TRANSACTED")) {
        sessionAckMode = Session.SESSION_TRANSACTED;
    } else {
        sessionAckMode = 1;
    }

    createConnectionFactory();
}

From source file:tools.ConsumerTool.java

public void parseCommandLine(String[] args) {
    CommandLineParser parser = new PosixParser();

    Options options = new Options();

    Option ackModeOpt = OptionBuilder.withLongOpt("acknowledgement-mode").withArgName("ackMode").hasArg()
            .withDescription(/*from   www.  ja v a2s. c o m*/
                    "session acknowledgement mode: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE")
            .create("a");
    options.addOption(ackModeOpt);

    Option browserOpt = OptionBuilder.withLongOpt("queue-browser").withDescription("create a queue browser")
            .create("b");
    options.addOption(browserOpt);

    Option clientIdOpt = OptionBuilder.withLongOpt("client-id").withArgName("id").hasArg()
            .withDescription("client id string that can optionally be set on a connection").create("c");
    options.addOption(clientIdOpt);

    Option durableOpt = OptionBuilder.withLongOpt("durable").withDescription("create a durable subscriber")
            .create("d");
    options.addOption(durableOpt);

    Option perMessageSleepOpt = OptionBuilder.withLongOpt("per-message-sleep").withArgName("millis").hasArg()
            .withDescription("amount of time (in ms) to sleep after receiving each message").create("e");
    options.addOption(perMessageSleepOpt);

    Option connFactOpt = OptionBuilder.withLongOpt("connection-factory-name").withArgName("name").hasArg()
            .withDescription("name of the connection factory to lookup").create("f");
    options.addOption(connFactOpt);

    Option numThreadsOpt = OptionBuilder.withLongOpt("num-threads").withArgName("num").hasArg()
            .withDescription("number of threads to run in parallel each with a connection").create("g");
    options.addOption(numThreadsOpt);

    Option helpOpt = OptionBuilder.withLongOpt("help").withDescription("show help").create("h");
    options.addOption(helpOpt);

    Option jndiDestOpt = OptionBuilder.withLongOpt("jndi-lookup-destination")
            .withDescription("lookup destinations with jndi").create("j");
    options.addOption(jndiDestOpt);

    Option selectorOpt = OptionBuilder.withLongOpt("message-selector").withArgName("selector").hasArg()
            .withDescription("message selector to use when creating consumer").create("k");
    options.addOption(selectorOpt);

    Option numMessagesOpt = OptionBuilder.withLongOpt("num-messages").withArgName("num").hasArg()
            .withDescription("number of messages to receive before stopping").create("m");
    options.addOption(numMessagesOpt);

    Option destNameOpt = OptionBuilder.withLongOpt("destination-name").withArgName("name").hasArg()
            .withDescription("name of the destination to receive from").create("n");
    options.addOption(destNameOpt);

    Option tempOpt = OptionBuilder.withLongOpt("temporary-destination")
            .withDescription("use a temporary destination").create("p");
    options.addOption(tempOpt);

    Option useQueueOpt = OptionBuilder.withLongOpt("queue-destination")
            .withDescription("use a queue destination").create("q");
    options.addOption(useQueueOpt);

    Option receiveTimeoutOpt = OptionBuilder.withLongOpt("receive-timeout").withArgName("millis").hasArg()
            .withDescription("blocking receive timeout (-1 indicates blocking receive call with no timeout)")
            .create("r");
    options.addOption(receiveTimeoutOpt);

    Option subscriptionOpt = OptionBuilder.withLongOpt("subscription-name").withArgName("subName").hasArg()
            .withDescription("subscription name to use when creating a durable subscriber").create("s");
    options.addOption(subscriptionOpt);

    Option transOpt = OptionBuilder.withLongOpt("transacted").withDescription("use a transacted session")
            .create("t");
    options.addOption(transOpt);

    Option asyncOpt = OptionBuilder.withLongOpt("async-listener")
            .withDescription("use an async message listener instead of consumer receive calls").create("y");
    options.addOption(asyncOpt);

    Option batchSizeOpt = OptionBuilder.withLongOpt("batch-size").withArgName("size").hasArg()
            .withDescription(
                    "size of the batch to ack or commit when using client ack mode or transacted sessions")
            .create("z");
    options.addOption(batchSizeOpt);

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("h")) {
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("ConsumerTool", options, true);
            System.exit(0);
        }

        if (line.hasOption("a")) {
            String ackModeStr = line.getOptionValue("a");
            if (ackModeStr.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) {
                acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("CLIENT_ACKNOWLEDGE")) {
                acknowledgeMode = Session.CLIENT_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) {
                acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("SESSION_TRANSACTED")) {
                acknowledgeMode = Session.SESSION_TRANSACTED;
            } else {
                throw new ParseException("Invalid value for acknowledge mode: " + ackModeStr);
            }
        }

        if (line.hasOption("b")) {
            useQueueBrowser = true;
        }

        if (line.hasOption("c")) {
            clientId = line.getOptionValue("c");
        }

        if (line.hasOption("d")) {
            durable = true;
        }

        if (line.hasOption("e")) {
            perMessageSleepMS = Integer.parseInt(line.getOptionValue("e"));
        }

        if (line.hasOption("f")) {
            connectionFactoryName = line.getOptionValue("f");
        }

        if (line.hasOption("g")) {
            numThreads = Integer.parseInt(line.getOptionValue("g"));
        }

        if (line.hasOption("j")) {
            jndiLookupDestinations = true;
        }

        if (line.hasOption("k")) {
            selector = line.getOptionValue("k");
        }

        if (line.hasOption("m")) {
            numMessages = Integer.parseInt(line.getOptionValue("m"));
        }

        if (line.hasOption("n")) {
            destinationName = line.getOptionValue("n");
        }

        if (line.hasOption("p")) {
            useTemporaryDestinations = true;
        }

        if (line.hasOption("q")) {
            useQueueDestinations = true;
        }

        if (line.hasOption("r")) {
            receiveTimeoutMS = Integer.parseInt(line.getOptionValue("r"));
        }

        if (line.hasOption("s")) {
            subscriptionName = line.getOptionValue("s");
        }

        if (line.hasOption("t")) {
            transacted = true;
        }

        if (line.hasOption("y")) {
            useAsyncListener = true;
        }

        if (line.hasOption("z")) {
            batchSize = Integer.parseInt(line.getOptionValue("z"));
        }

    } catch (ParseException exp) {
        LOGGER.error("Commandline parsing exception: " + exp.getMessage(), exp);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ConsumerTool", options, true);
        System.exit(-1);
    }
}

From source file:tools.ProducerTool.java

public void parseCommandLine(String[] args) {
    CommandLineParser parser = new PosixParser();

    Options options = new Options();

    Option ackModeOpt = OptionBuilder.withLongOpt("acknowledgement-mode").withArgName("ackMode").hasArg()
            .withDescription(//from   ww w .ja v  a 2  s.c om
                    "session acknowledgement mode: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE")
            .create("a");
    options.addOption(ackModeOpt);

    Option clientIdOpt = OptionBuilder.withLongOpt("client-id").withArgName("id").hasArg()
            .withDescription("client id string that can optionally be set on a connection").create("c");
    options.addOption(clientIdOpt);

    Option durableOpt = OptionBuilder.withLongOpt("durable").withDescription("create a durable subscriber")
            .create("d");
    options.addOption(durableOpt);

    Option perMessageSleepOpt = OptionBuilder.withLongOpt("per-message-sleep").withArgName("millis").hasArg()
            .withDescription("amount of time (in ms) to sleep after receiving each message").create("e");
    options.addOption(perMessageSleepOpt);

    Option connFactOpt = OptionBuilder.withLongOpt("connection-factory-name").withArgName("name").hasArg()
            .withDescription("name of the connection factory to lookup").create("f");
    options.addOption(connFactOpt);

    Option numThreadsOpt = OptionBuilder.withLongOpt("num-threads").withArgName("num").hasArg()
            .withDescription("number of threads to run in parallel each with a connection").create("g");
    options.addOption(numThreadsOpt);

    Option helpOpt = OptionBuilder.withLongOpt("help").withDescription("show help").create("h");
    options.addOption(helpOpt);

    Option jndiDestOpt = OptionBuilder.withLongOpt("jndi-lookup-destination")
            .withDescription("lookup destinations with jndi").create("j");
    options.addOption(jndiDestOpt);

    Option bytesLengthOpt = OptionBuilder.withLongOpt("bytes-message-length").withArgName("length").hasArg()
            .withDescription("use a bytes message of a specific length").create("l");
    options.addOption(bytesLengthOpt);

    Option numMessagesOpt = OptionBuilder.withLongOpt("num-messages").withArgName("num").hasArg()
            .withDescription("number of messages to receive before stopping").create("m");
    options.addOption(numMessagesOpt);

    Option destNameOpt = OptionBuilder.withLongOpt("destination-name").withArgName("name").hasArg()
            .withDescription("name of the destination to receive from").create("n");
    options.addOption(destNameOpt);

    Option controlOpt = OptionBuilder.withLongOpt("final-control-message")
            .withDescription("use a control message as the final message").create("o");
    options.addOption(controlOpt);

    Option tempOpt = OptionBuilder.withLongOpt("temporary-destination")
            .withDescription("use a temporary destination").create("p");
    options.addOption(tempOpt);

    Option useQueueOpt = OptionBuilder.withLongOpt("queue-destination")
            .withDescription("use a queue destination").create("q");
    options.addOption(useQueueOpt);

    Option transOpt = OptionBuilder.withLongOpt("transacted").withDescription("use a transacted session")
            .create("t");
    options.addOption(transOpt);

    Option groupIdOpt = OptionBuilder.withLongOpt("message-group-id").withArgName("groupId").hasArg()
            .withDescription("JMSXGroupID").create("x");
    options.addOption(groupIdOpt);

    Option batchSizeOpt = OptionBuilder.withLongOpt("batch-size").withArgName("size").hasArg()
            .withDescription(
                    "size of the batch to ack or commit when using client ack mode or transacted sessions")
            .create("z");
    options.addOption(batchSizeOpt);

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("h")) {
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("ProducerTool", options, true);
            System.exit(0);
        }

        if (line.hasOption("a")) {
            String ackModeStr = line.getOptionValue("a");
            if (ackModeStr.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) {
                acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("CLIENT_ACKNOWLEDGE")) {
                acknowledgeMode = Session.CLIENT_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) {
                acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("SESSION_TRANSACTED")) {
                acknowledgeMode = Session.SESSION_TRANSACTED;
            } else {
                throw new ParseException("Invalid value for acknowledge mode: " + ackModeStr);
            }
        }

        if (line.hasOption("c")) {
            clientId = line.getOptionValue("c");
        }

        if (line.hasOption("d")) {
            durable = true;
        }

        if (line.hasOption("e")) {
            perMessageSleepMS = Integer.parseInt(line.getOptionValue("e"));
        }

        if (line.hasOption("f")) {
            connectionFactoryName = line.getOptionValue("f");
        }

        if (line.hasOption("g")) {
            numThreads = Integer.parseInt(line.getOptionValue("g"));
        }

        if (line.hasOption("j")) {
            jndiLookupDestinations = true;
        }

        if (line.hasOption("l")) {
            bytesLength = Integer.parseInt(line.getOptionValue("l"));
        }

        if (line.hasOption("m")) {
            numMessages = Integer.parseInt(line.getOptionValue("m"));
        }

        if (line.hasOption("n")) {
            destinationName = line.getOptionValue("n");
        }

        if (line.hasOption("o")) {
            useFinalControlMessage = true;
        }

        if (line.hasOption("p")) {
            useTemporaryDestinations = true;
        }

        if (line.hasOption("q")) {
            useQueueDestinations = true;
        }

        if (line.hasOption("t")) {
            transacted = true;
        }

        if (line.hasOption("x")) {
            messageGroupId = line.getOptionValue("x");
        }

        if (line.hasOption("z")) {
            batchSize = Integer.parseInt(line.getOptionValue("z"));
        }

    } catch (ParseException exp) {
        LOGGER.error("Commandline parsing exception: " + exp.getMessage(), exp);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ProducerTool", options, true);
        System.exit(-1);
    }
}