Example usage for javax.jms MapMessage setString

List of usage examples for javax.jms MapMessage setString

Introduction

In this page you can find the example usage for javax.jms MapMessage setString.

Prototype


void setString(String name, String value) throws JMSException;

Source Link

Document

Sets a String value with the specified name into the Map.

Usage

From source file:org.apache.falcon.messaging.JMSMessageConsumerTest.java

private Message getMockFalconMessage(int i, Session session) throws FalconException, JMSException {
    Map<String, String> message = new HashMap<String, String>();
    message.put(WorkflowExecutionArgs.BRKR_IMPL_CLASS.getName(), BROKER_IMPL_CLASS);
    message.put(WorkflowExecutionArgs.BRKR_URL.getName(), BROKER_URL);
    message.put(WorkflowExecutionArgs.CLUSTER_NAME.getName(), "cluster1");
    message.put(WorkflowExecutionArgs.ENTITY_NAME.getName(), "process1");
    message.put(WorkflowExecutionArgs.ENTITY_TYPE.getName(), "PROCESS");
    message.put(WorkflowExecutionArgs.OUTPUT_FEED_PATHS.getName(), "/clicks/hour/00/0" + i);
    message.put(WorkflowExecutionArgs.OUTPUT_FEED_NAMES.getName(), "clicks");
    message.put(WorkflowExecutionArgs.LOG_FILE.getName(), "/logfile");
    message.put(WorkflowExecutionArgs.LOG_DIR.getName(), "/tmp/falcon-log");
    message.put(WorkflowExecutionArgs.NOMINAL_TIME.getName(), "2012-10-10-10-10");
    message.put(WorkflowExecutionArgs.OPERATION.getName(), "GENERATE");
    message.put(WorkflowExecutionArgs.RUN_ID.getName(), "0");
    message.put(WorkflowExecutionArgs.TIMESTAMP.getName(), "2012-10-10-10-1" + i);
    message.put(WorkflowExecutionArgs.WORKFLOW_ID.getName(), "workflow-" + i);
    message.put(WorkflowExecutionArgs.TOPIC_NAME.getName(), TOPIC_NAME);
    message.put(WorkflowExecutionArgs.STATUS.getName(), i != 15 ? "SUCCEEDED" : "FAILED");
    message.put(WorkflowExecutionArgs.WORKFLOW_USER.getName(), FalconTestUtil.TEST_USER_1);

    String[] args = new String[message.size() * 2];
    int index = 0;
    for (Map.Entry<String, String> entry : message.entrySet()) {
        args[index++] = "-" + entry.getKey();
        args[index++] = entry.getValue();
    }/*from  w  w w  . j a  v  a 2  s . c om*/

    WorkflowExecutionContext context = WorkflowExecutionContext.create(args,
            WorkflowExecutionContext.Type.POST_PROCESSING);

    MapMessage jmsMessage = session.createMapMessage();
    for (Map.Entry<WorkflowExecutionArgs, String> entry : context.entrySet()) {
        jmsMessage.setString(entry.getKey().getName(), entry.getValue());
    }

    return jmsMessage;
}

From source file:org.egov.infra.messaging.MessagingService.java

public void sendEmail(final String email, final String subject, final String message) {
    if (applicationProperties.emailEnabled() && isNoneBlank(email, subject, message))
        jmsTemplate.send(emailQueue, session -> {
            final MapMessage mapMessage = session.createMapMessage();
            mapMessage.setString("email", email);
            mapMessage.setString("message", message);
            mapMessage.setString("subject", subject);
            return mapMessage;
        });/*  ww  w.  ja v a2 s .  c  o  m*/
}

From source file:org.egov.infra.messaging.MessagingService.java

public void sendSMS(final String mobileNo, final String message) {
    if (applicationProperties.smsEnabled() && isNoneBlank(mobileNo, message))
        jmsTemplate.send(smsQueue, session -> {
            final MapMessage mapMessage = session.createMapMessage();
            mapMessage.setString("mobile", "91" + mobileNo);
            mapMessage.setString("message", message);
            return mapMessage;
        });/*w  w w  . jav a 2s  .co m*/
}

From source file:org.egov.infra.notification.service.NotificationService.java

public void sendEmail(String email, String subject, String message) {
    if (mailEnabled && isNoneBlank(email, subject, message))
        jmsTemplate.send(emailQueue, session -> {
            MapMessage mapMessage = session.createMapMessage();
            mapMessage.setString(EMAIL, email);
            mapMessage.setString(MESSAGE, message);
            mapMessage.setString(SUBJECT, subject);
            return mapMessage;
        });/*from w ww  .j  a  v a  2  s . c o m*/
}

From source file:org.egov.infra.notification.service.NotificationService.java

public void sendEmailWithAttachment(String email, String subject, String message, String fileType,
        String fileName, byte[] attachment) {
    if (mailEnabled && isNoneBlank(email, subject, message))
        jmsTemplate.send(emailQueue, session -> {
            MapMessage mapMessage = session.createMapMessage();
            mapMessage.setString(EMAIL, email);
            mapMessage.setString(MESSAGE, message);
            mapMessage.setString(SUBJECT, subject);
            mapMessage.setString(FILETYPE, fileType);
            mapMessage.setString(FILENAME, fileName);
            mapMessage.setBytes(ATTACHMENT, attachment);
            return mapMessage;
        });//from  w  w w .  ja  v a2  s.co  m
}

From source file:org.egov.infra.notification.service.NotificationService.java

public void sendSMS(String mobileNo, String message, NotificationPriority priority) {
    if (smsEnabled && isNoneBlank(mobileNo, message))
        jmsTemplate.send(HIGH.equals(priority) ? flashQueue : smsQueue, session -> {
            MapMessage mapMessage = session.createMapMessage();
            mapMessage.setString(MOBILE, mobileNo);
            mapMessage.setString(MESSAGE, message);
            mapMessage.setString(PRIORITY, priority.name());
            return mapMessage;
        });/*  www  .ja  va  2 s .  c o m*/
}

From source file:org.jbpm.bpel.tutorial.shipping.ShippingPT_Impl.java

protected void sendShippingMessage(String customerId) throws JMSException {
    // create a session
    Session jmsSession = jmsConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    try {/*from   w  w w .  ja v  a 2s  . c  o m*/
        // create the message
        MapMessage message = jmsSession.createMapMessage();
        message.setString("customerId", customerId);

        // send it!
        MessageProducer producer = jmsSession.createProducer(shippingDestination);
        producer.send(message);

        log.debug("Sent shipping message: customerId=" + customerId);
    } finally {
        jmsSession.close();
    }
}

From source file:org.wso2.carbon.appfactory.eventing.jms.TopicPublisher.java

public void publishMessage(Event event) throws AppFactoryEventException {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
    properties.put(CF_NAME_PREFIX + CF_NAME, Util.getTCPConnectionURL());
    properties.put(CarbonConstants.REQUEST_BASE_CONTEXT, "true");
    try {//from w ww .  ja va 2  s .  c  o  m
        ctx = new InitialContext(properties);
        connFactory = (TopicConnectionFactory) ctx.lookup(CF_NAME);
    } catch (NamingException e) {
        throw new AppFactoryEventException("Failed to initialize InitialContext.", e);
    }

    TopicConnection topicConnection = null;
    TopicSession topicSession = null;
    try {
        topicConnection = connFactory.createTopicConnection();
        topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
        // Send message
        String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        Topic topic = topicSession.createTopic(event.getTarget());

        //Until MB supports 'Dynamic Topics' we have to create a subscription, therefore forcing Message broker to
        // create the topic.
        String defaultSubscriptionId = tenantDomain + "/" + DEFAULT_SUBSCRIPTION + UUID.randomUUID();
        topicSubscriber = topicSession.createDurableSubscriber(topic, defaultSubscriptionId);
        // We are unsubscribing from the Topic as soon as
        topicSession.unsubscribe(defaultSubscriptionId);

        // create the message to send
        MapMessage mapMessage = topicSession.createMapMessage();
        mapMessage.setString(MESSAGE_TITLE, event.getMessageTitle());
        mapMessage.setString(MESSAGE_BODY, event.getMessageBody());
        javax.jms.TopicPublisher topicPublisher = topicSession.createPublisher(topic);
        topicConnection.start();
        topicPublisher.publish(mapMessage);
        if (log.isDebugEnabled()) {
            log.debug("Message with Id:" + mapMessage.getJMSMessageID() + ", with title:"
                    + event.getMessageTitle() + " was successfully published.");
        }

    } catch (JMSException e) {
        log.error("Failed to publish message due to " + e.getMessage(), e);
        throw new AppFactoryEventException("Failed to publish message due to " + e.getMessage(), e);
    } finally {
        if (topicSubscriber != null) {
            try {
                topicSubscriber.close();
            } catch (JMSException e) {
                log.error("Failed to close default topic subscriber", e);
            }
        }
        if (topicSession != null) {
            try {
                topicSession.close();
            } catch (JMSException e) {
                log.error("Failed to close topic session", e);
            }
        }
        if (topicConnection != null) {
            try {
                topicConnection.close();
            } catch (JMSException e) {
                log.error("Failed to close topic connection", e);
            }
        }
    }
}

From source file:org.wso2.carbon.appfactory.s4.integration.TenantStratosSubscriptionMessagePublisher.java

/**
 * Publish message to MB/ActiveMQ Queue//from   www .  j a  v a 2s  .  co m
 * @param runtimeJson runtimebeans as a json
 * @param tenantInfoJson tenantInfoBean as a json
 * @param restServiceProperties propertyMap
 * @param stage current stage
 * @throws AppFactoryEventException
 */
public void publishMessage(String runtimeJson, String tenantInfoJson, Map<String, String> restServiceProperties,
        String stage) throws AppFactoryEventException {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, AppFactoryConstants.ANDES_ICF);
    properties.put(AppFactoryConstants.CF_NAME_PREFIX + AppFactoryConstants.CF_NAME,
            Util.getTCPConnectionURL());
    properties.put(AppFactoryConstants.TOPIC, topicName);
    TopicConnection topicConnection = null;
    TopicSession topicSession = null;
    try {
        ctx = new InitialContext(properties);
        connFactory = (TopicConnectionFactory) ctx.lookup(AppFactoryConstants.CF_NAME);
        topicConnection = connFactory.createTopicConnection();
        topicConnection.start();
        topicSession = topicConnection.createTopicSession(false, TopicSession.CLIENT_ACKNOWLEDGE);
        Topic topic = topicSession.createTopic(topicName);
        MapMessage mapMessage = topicSession.createMapMessage();
        mapMessage.setString(AppFactoryConstants.STAGE, stage);
        mapMessage.setString(AppFactoryConstants.RUNTIMES_INFO, runtimeJson);
        mapMessage.setString(AppFactoryConstants.TENANT_INFO, tenantInfoJson);
        javax.jms.TopicPublisher topicPublisher = topicSession.createPublisher(topic);
        topicPublisher.publish(mapMessage);

        //TODO remove this log
        log.info("Message with Id:" + mapMessage.getJMSMessageID() + " was successfully published to the"
                + " topic " + topicName);

        if (log.isDebugEnabled()) {
            log.debug("Message with Id:" + mapMessage.getJMSMessageID() + " was successfully published to the"
                    + " topic " + topicName);
        }
    } catch (NamingException e) {
        String msg = "Failed to initialize InitialContext";
        throw new AppFactoryEventException(msg, e);
    } catch (JMSException e) {
        String msg = "Failed to publish message due to " + e.getMessage();
        throw new AppFactoryEventException(msg, e);
    } finally {
        if (topicSession != null) {
            try {
                topicSession.close();
            } catch (JMSException e) {
                log.error("Failed to close topic session", e);
            }
        }
        if (topicConnection != null) {
            try {
                topicConnection.close();
            } catch (JMSException e) {
                log.error("Failed to close topic connection", e);
            }
        }
    }

}

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

public static void convertXMLtoJMSMap(OMElement element, MapMessage message) throws JMSException {

    Iterator itr = element.getChildElements();
    while (itr.hasNext()) {
        OMElement elem = (OMElement) itr.next();
        message.setString(elem.getLocalName(), elem.getText());
    }/*from   w w  w  . j  a  va  2s  . co m*/
}