| /* |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| * Loetz GmbH&Co.KG |
| * |
| */ |
| |
| package org.eclipse.osbp.webserver.messagequeue; |
| |
| import java.util.Map; |
| |
| import javax.jms.DeliveryMode; |
| import javax.jms.Destination; |
| import javax.jms.JMSException; |
| import javax.jms.MapMessage; |
| import javax.jms.MessageProducer; |
| import javax.jms.Session; |
| |
| import org.apache.log4j.Logger; |
| |
| /** |
| * Dieses gesamte Package muss zum jetzigen Zeitpunkt <b>manuell</b> dupliziert und synchronisiert werden<ul> |
| * <li><a href="http://10.1.2.27:8100/cc360/browser/OSGI-Plugins/org.eclipse.osbp.webserver.messagequeue">cc360/OSGI-Plugins/org.eclipse.osbp.webserver.messagequeue</a></li> |
| * <li><a href="http://10.1.2.27:8100/kapstadt/browser/development2/3.50/src/cxj/diamond7/src/webclt-webserver/org/eclipse/osbp/webserver/messagequeue">cc3.50/development2/3.50/src/cxj/diamond7/src/webclt-webserver/org/eclipse/osbp/webserver/messagequeue</a></li> |
| * </ul> |
| * Send/produce messages via ActiveMQ |
| */ |
| public class CXMqProducer { |
| |
| /** The local session. */ |
| private final Session fLocalSession; |
| |
| /** The remote queue name. */ |
| private final String fRemoteQueueName; |
| |
| /** The remote destination. */ |
| private final Destination fRemoteDestination; |
| |
| /** The logger. */ |
| private final Logger LOGGER; |
| |
| /** |
| * Create the producer instance. |
| * |
| * @param session |
| * the session |
| * @param remoteQueueName |
| * the remote queue name |
| * @param logger |
| * the logger |
| */ |
| protected CXMqProducer(Session session, String remoteQueueName, Logger logger) { |
| fLocalSession = session; |
| fRemoteQueueName = remoteQueueName; |
| LOGGER = logger; |
| Destination destination = null; |
| try { |
| destination = fLocalSession.createQueue(fRemoteQueueName); |
| } |
| catch (Exception e) { |
| if (LOGGER != null) { |
| LOGGER.error(e); |
| } |
| else { |
| System.err.println(e); |
| } |
| } |
| fRemoteDestination = destination; |
| } |
| |
| /** |
| * generate a message and send/produce it via ActiveMQ. |
| * |
| * @param event |
| * type of event |
| * @param body |
| * attribute/value pairs depending on type of event |
| * @throws JMSException |
| * the JMS exception |
| */ |
| protected void sendMessage(ECXMqMessageEvent event, Map<ECXMqMessageAttribute,Object> body) throws JMSException { |
| try { |
| MessageProducer producer = fLocalSession.createProducer(fRemoteDestination); |
| producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); |
| MapMessage message = fLocalSession.createMapMessage(); |
| message.setStringProperty(ECXMqMessageEvent.EVENT, event.toString()); |
| if (body != null) { |
| for (ECXMqMessageAttribute key : body.keySet()) { |
| key.setValue(message, body.get(key)); |
| } |
| } |
| producer.send(message); |
| } |
| catch (Exception e) { |
| if (LOGGER != null) { |
| LOGGER.error(e); |
| } |
| else { |
| System.err.println(e); |
| } |
| } |
| } |
| } |