Example usage for javax.jms Session createTextMessage

List of usage examples for javax.jms Session createTextMessage

Introduction

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

Prototype


TextMessage createTextMessage(String text) throws JMSException;

Source Link

Document

Creates an initialized TextMessage object.

Usage

From source file:org.fatal1t.forexapp.spring.api.adapters.SyncListener.java

private void sendMessage(String message, String CorelId, Destination queue)
        throws JmsException, BeansException {
    MessageCreator messageCreator = (javax.jms.Session session1) -> {
        Message nMessage = session1.createTextMessage(message);
        nMessage.setJMSCorrelationID(CorelId);

        return nMessage;
    };/*  w  w w.  j ava 2s. c om*/

    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    log.info("Target queue: " + queue.toString());
    log.info("Sending back: " + CorelId + " " + message.substring(0, 10));
    jmsTemplate.send(queue, messageCreator);
}

From source file:com.inkubator.sms.gateway.service.impl.SchedullerSendingSmsServiceImpl.java

private void sendingSms(TaskDefinition taskDefinition) {
    final SMSSend sendModel = new SMSSend();
    Gson gson = new GsonBuilder().create();
    TypeToken<List<String>> token = new TypeToken<List<String>>() {
    };//from   ww  w  . jav a 2  s.c  o  m
    List<String> toLoop = gson.fromJson(taskDefinition.getDestination(), token.getType());
    for (String notlp : toLoop) {
        sendModel.setPricePerSms(taskDefinition.getModemDefinition().getPricePerSms());
        sendModel.setContent(taskDefinition.getSmsContent());
        sendModel.setFrom("System");
        sendModel.setDestination(notlp);
        sendModel.setModemId(taskDefinition.getModemDefinition().getModemId());
        this.jmsTemplateSMS.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage(jsonConverter.getJson(sendModel));
            }
        });

    }
}

From source file:samples.jms.producercallback.ProducerCallbackExampleTests.java

@Test
public void testProducer() throws Exception {

    jmsTemplate.execute(new ProducerCallback<Object>() {
        public Object doInJms(Session session, MessageProducer producer) throws JMSException {
            for (int i = 1; i <= 10; i++) {
                Message message = session.createTextMessage("Hello #" + i);
                producer.send(destination, message);
            }/*ww w  .  j  a v a  2 s.  c o  m*/
            return null;
        }
    });
}

From source file:io.datalayer.activemq.producer.SpringProducer.java

public void start() throws JMSException {
    for (int i = 0; i < messageCount; i++) {
        final String text = "Text for message: " + i;
        template.send(destination, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                LOG.info("Sending message: " + text);
                TextMessage message = session.createTextMessage(text);
                message.setStringProperty("next", "foo");
                return message;
            }/*from  w w w  . ja va 2  s  . c  om*/
        });
    }
}

From source file:jms001.ExampleListener.java

@JmsListener(destination = "INBOUND")
public JmsResponse inbound(Message message, Session s) throws JMSException {
    String dst = "D" + (1 + counter.incrementAndGet() % 3);
    System.out.println("sent to: " + dst);
    return JmsResponse.forQueue(s.createTextMessage("What a beautiful world!"), dst);
}

From source file:org.logicblaze.lingo.jms.marshall.XStreamMarshaller.java

public Message createObjectMessage(Session session, Object value) throws JMSException {
    String xml = toXML(value);/*w  ww . j  a  v  a2 s.co m*/
    TextMessage message = session.createTextMessage(xml);
    appendMessageHeaders(message, session, value);
    return message;
}

From source file:org.powertac.samplebroker.core.MessageDispatcher.java

/**
 * Sends outgoing messages to the server
 *///from   w w  w . j  a v  a2  s. com
public void sendMessage(Object message) {
    if (!validateId(message))
        return;
    final String text = key + converter.toXML(message);
    log.info("sending text: \n" + text);

    template.send(jmsManagementService.getServerQueueName(), new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage(text);
            return message;
        }
    });
}

From source file:org.openbaton.common.vnfm_sdk.amqp.VnfmSpringHelper.java

public MessageCreator getTextMessageCreator(final String string) {
    MessageCreator messageCreator = new MessageCreator() {
        @Override//from   w w  w . j a v  a2 s .  co m
        public Message createMessage(Session session) throws JMSException {
            TextMessage objectMessage = session.createTextMessage(string);
            return objectMessage;
        }
    };
    return messageCreator;
}

From source file:be.anova.courses.activemq.MessageTimerTask.java

@Override
public void run() {
    if (enabled) {
        template.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                String message = String.format("Message sent at %tc", new Date());
                return session.createTextMessage(message);
            }/*from w  w  w.ja v a2s.  c  o  m*/
        });
    }
}

From source file:net.lr.jmsbridge.BridgeServlet.java

/**
 * Forward HTTP request to a jms queue and listen on a temporary queue for the reply.
 * Connects to the jms server by using the username and password from the HTTP basic auth.
 *///from  w w w. ja va2  s  .co m
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String authHeader = req.getHeader("Authorization");
    if (authHeader == null) {
        resp.setHeader("WWW-Authenticate", "Basic realm=\"Bridge\"");
        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "auth");
        return;
    }
    UserNameAndPassword auth = extractUserNamePassword(authHeader);
    PrintStream out = new PrintStream(resp.getOutputStream());
    String contextPath = req.getContextPath();
    String uri = req.getRequestURI();
    String queueName = uri.substring(contextPath.length() + 1);
    final StringBuffer reqContent = retrieveRequestContent(req.getReader());

    ConnectionFactory cf = connectionPool.getConnectionFactory(auth);
    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(cf);
    jmsTemplate.setReceiveTimeout(10000);
    final Destination replyDest = connectionPool.getReplyDestination(cf, auth);
    jmsTemplate.send(queueName, new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage(reqContent.toString());
            message.setJMSReplyTo(replyDest);
            return message;
        }

    });
    Message replyMsg = jmsTemplate.receive(replyDest);
    if (replyMsg instanceof TextMessage) {
        TextMessage replyTMessage = (TextMessage) replyMsg;
        try {
            out.print(replyTMessage.getText());
        } catch (JMSException e) {
            JmsUtils.convertJmsAccessException(e);
        }
    }
}