Example usage for org.springframework.jms.core JmsTemplate setDeliveryMode

List of usage examples for org.springframework.jms.core JmsTemplate setDeliveryMode

Introduction

In this page you can find the example usage for org.springframework.jms.core JmsTemplate setDeliveryMode.

Prototype

public void setDeliveryMode(int deliveryMode) 

Source Link

Document

Set the delivery mode to use when sending a message.

Usage

From source file:com.jim.im.config.GenericMQConfig.java

@Bean
public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory, JmsProperties properties,
        MessageConverter messageConverter, DestinationResolver destinationResolver) {
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    jmsTemplate.setMessageConverter(messageConverter);
    jmsTemplate.setPubSubDomain(properties.isPubSubDomain());
    jmsTemplate.setDeliveryMode(Session.AUTO_ACKNOWLEDGE);
    if (destinationResolver != null) {
        jmsTemplate.setDestinationResolver(destinationResolver);
    }//from   ww w.  java2 s  . c o m
    jmsTemplate.setDefaultDestinationName(IMConstant.MQ_FORWARD_TOPIC_NAME);
    return jmsTemplate;
}

From source file:com.atlantbh.jmeter.plugins.jmstools.JmsUtil.java

@Override
public SampleResult runTest(JavaSamplerContext ctx) {

    SampleResult result = new SampleResult();
    result.setContentType("plain/text");
    result.setDataType(SampleResult.TEXT);
    result.setDataEncoding(SampleResult.DEFAULT_HTTP_ENCODING);

    String connectionUrl = ctx.getParameter("connection.url");
    String bindingUrl = ctx.getParameter("binding.url");
    String message = ctx.getParameter("message");

    if (connectionUrl == null || "".equals(connectionUrl)) {
        result.setSuccessful(false);/* ww  w .ja  v  a 2s.co  m*/
        result.setResponseMessage("Connection URL cannot be empty.");
        result.setResponseCode("0xDEAD");
    } else {
        if (bindingUrl == null || "".equals(bindingUrl)) {
            result.setSuccessful(false);
            result.setResponseMessage("Binding URL cannot be empty.");
            result.setResponseCode("0xDEAD");
        } else {
            try {
                ConnectionFactory connectionFactory = new AMQConnectionFactory(connectionUrl);
                AMQBindingURL burl = new AMQBindingURL(bindingUrl);

                Destination destinationProducer = new AMQAnyDestination(burl);
                JmsTemplate sender = new JmsTemplate();
                sender.setConnectionFactory(connectionFactory);
                sender.setDefaultDestination(destinationProducer);
                BinaryMessageConverter bmc = new BinaryMessageConverter();
                sender.setMessageConverter(bmc);

                BinaryMessagepostProcessor postProcessor = new BinaryMessagepostProcessor();

                sender.setDeliveryMode(2);
                int rt = 30000;
                try {
                    rt = Integer.valueOf(ctx.getParameter("receive.timeout"));
                } catch (Exception e) {
                }

                sender.setReceiveTimeout(rt);

                String direction = ctx.getParameter("direction");
                if (direction == null || "".equals(direction)) {
                    direction = "send";
                }
                if (direction.toLowerCase().equals("send")) {
                    Map<String, String> mp = getMessageProperties(ctx.getParameter("header.properties"));
                    postProcessor.setMessageProperties(mp);
                    sender.convertAndSend((Object) message, postProcessor);
                    result.setSuccessful(true);
                    result.setResponseMessage("Message sent.");
                } else {
                    if (direction.toLowerCase().equals("receive")) {

                        System.out.println("Receive");
                        String messageSelector = ctx.getParameter("message.selector");
                        System.out.println("Selector: " + messageSelector);
                        Object obj = null;
                        if (messageSelector != null && !"".equals(messageSelector)) {
                            obj = sender.receiveSelectedAndConvert(messageSelector);
                        } else {
                            obj = sender.receiveAndConvert();
                        }

                        if (obj != null) {
                            result.setSuccessful(true);
                            result.setResponseData(obj.toString().getBytes());
                            String paramName = ctx.getParameter("header.property.reference");
                            if (paramName != null && !"".equals(paramName))
                                JMeterUtils.setProperty(paramName,
                                        concatProperties(bmc.getMessageProperties()));
                        } else {
                            result.setSuccessful(false);
                            result.setResponseData("Conection timeout".getBytes());

                        }

                    } else {
                        result.setSuccessful(false);
                        result.setResponseMessage("Unknown direction.");

                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                result.setSuccessful(!true);
                result.setResponseMessage("Exception");
                result.setResponseData(e.getMessage().getBytes());
            }

        }

    }

    return result;
}

From source file:org.apache.servicemix.jms.endpoints.JmsProviderEndpoint.java

/**
 * Create the JMS template to be used to send the JMS messages.
 *
 * @return/*  ww  w.  j  a  v a 2 s.  c o  m*/
 */
protected JmsTemplate createTemplate() {
    JmsTemplate tplt;
    if (isJms102()) {
        tplt = new JmsTemplate102();
    } else {
        tplt = new JmsTemplate();
    }
    tplt.setConnectionFactory(getConnectionFactory());
    if (getDestination() != null) {
        tplt.setDefaultDestination(getDestination());
    } else if (getDestinationName() != null) {
        tplt.setDefaultDestinationName(getDestinationName());
    }
    tplt.setDeliveryMode(getDeliveryMode());
    if (getDestinationResolver() != null) {
        tplt.setDestinationResolver(getDestinationResolver());
    }
    tplt.setExplicitQosEnabled(isExplicitQosEnabled());
    tplt.setMessageIdEnabled(isMessageIdEnabled());
    tplt.setMessageTimestampEnabled(isMessageTimestampEnabled());
    tplt.setPriority(getPriority());
    tplt.setPubSubDomain(isPubSubDomain());
    tplt.setPubSubNoLocal(isPubSubNoLocal());
    tplt.setTimeToLive(getTimeToLive());
    tplt.setReceiveTimeout(getReceiveTimeout());
    tplt.afterPropertiesSet();
    return tplt;
}