Package com.bhle.ingest.jms

Source Code of com.bhle.ingest.jms.PreingestJmsProducerStub

package com.bhle.ingest.jms;

import java.util.Map;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

@Component
public class PreingestJmsProducerStub {

  @Autowired
  @Qualifier(value = "preingestJmsProducerTemplate")
  private JmsTemplate template;

  public void send(final Map<String, String> messageBody) {
    template.send(new MessageCreator() {
      public Message createMessage(Session session) throws JMSException {
        JSONObject json = new JSONObject();
        for (String key : messageBody.keySet()) {
          json.put(key, messageBody.get(key));
        }
        TextMessage msg = session.createTextMessage(json.toString());
        return msg;
      }
    });
  }

}
TOP

Related Classes of com.bhle.ingest.jms.PreingestJmsProducerStub

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.