當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageConsumer.setMessageListener方法代碼示例

本文整理匯總了Java中javax.jms.MessageConsumer.setMessageListener方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageConsumer.setMessageListener方法的具體用法?Java MessageConsumer.setMessageListener怎麽用?Java MessageConsumer.setMessageListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.jms.MessageConsumer的用法示例。


在下文中一共展示了MessageConsumer.setMessageListener方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import javax.jms.MessageConsumer; //導入方法依賴的package包/類
/**
 * Inits the.
 *
 * @throws JMSException the jMS exception
 */
public void init() throws JMSException {

  connection = connFactory.createConnection();
  connection.setClientID(consumerName);
  session = connection.createSession(true, Session.SESSION_TRANSACTED);

  Queue queue = session.createQueue(queueName);

  MessageConsumer consumer = session.createConsumer(queue);
  consumer.setMessageListener(this);
  connection.start();

  logger.info(">>>>>>>>>>>>>>CmsListener Waiting for messages...");
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:20,代碼來源:CmsListener.java

示例2: JmsMessageSource

import javax.jms.MessageConsumer; //導入方法依賴的package包/類
/**
 * JMS Consumer and Converter to convert retrieve and convert Message.
 * @param consumer The consumer
 * @param converter The converter
 */
public JmsMessageSource(MessageConsumer consumer, JmsMessageConverter converter) {
  try {
    this.converter = converter;
    consumer.setMessageListener(this);
  } catch (JMSException ex) {
    throw new RuntimeException(ex);
  }
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:14,代碼來源:JmsMessageSource.java

示例3: init

import javax.jms.MessageConsumer; //導入方法依賴的package包/類
/**
 * Inits the.
 *
 * @throws JMSException the jMS exception
 */
public void init() throws JMSException {

  connection = connFactory.createConnection();
  // lets make it transactional
  session = connection.createSession(true, Session.SESSION_TRANSACTED);
  Queue controllerQueue = session.createQueue(ctrlrQueueName);

  MessageConsumer consumer = session.createConsumer(controllerQueue);

  consumer.setMessageListener(this);
  connection.start();

  logger.info(">>>>>>>>>>>>>>>>Inductor Listener Waiting for messages...");
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:20,代碼來源:InductorListener.java

示例4: startListener

import javax.jms.MessageConsumer; //導入方法依賴的package包/類
private void startListener(MessageHandler handler) {
    log.debug("Starting listener...");
    try {
        ActiveMQConnection connection = ActiveMqUtils.openConnection(user, password, url);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(queueInput);
        MessageConsumer consumer = session.createConsumer(queue);
        consumer.setMessageListener(message -> handleMessage(handler, message, session));
        log.debug("Listening to {}", queueInput);
    } catch (Exception e) {
        log.error("Error starting listening to queue {}", queueInput, e);
    }
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:14,代碼來源:ActiveMqListener.java

示例5: getHeartbeats

import javax.jms.MessageConsumer; //導入方法依賴的package包/類
/**
 *
 * @param uri
 * @param topicName
 * @param clazz
 * @param monitorTime
 * @return
 */
public Map<String, T> getHeartbeats(final URI uri, final String topicName, final Class<T> clazz, final long monitorTime) throws Exception {

	final Map<String, T> ret = new HashMap<String, T>(3);
	Connection topicConnection = null;
	try {
		ConnectionFactory connectionFactory  = (ConnectionFactory)service.createConnectionFactory(uri);
		topicConnection = connectionFactory.createConnection();
		topicConnection.start();

		Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

		final Topic           topic    = session.createTopic(topicName);
		final MessageConsumer consumer = session.createConsumer(topic);


		MessageListener listener = new MessageListener() {
			@Override
			public void onMessage(Message message) {
				try {
					if (message instanceof TextMessage) {
						TextMessage t = (TextMessage) message;
						final T bean = (T)service.unmarshal(t.getText(), clazz);
						Method nameMethod = bean.getClass().getMethod("getName");
						ret.put((String)nameMethod.invoke(bean), bean);
					}
				} catch (Exception e) {
					logger.error("Updating changed bean from topic", e);
				}
			}
		};
		consumer.setMessageListener(listener);
		Thread.sleep(monitorTime);

		return ret;

	} catch (Exception ne) {
		logger.error("Cannot listen to topic changes because command server is not there", ne);
		return null;
	} finally {
		topicConnection.close();
	}

}
 
開發者ID:eclipse,項目名稱:scanning,代碼行數:52,代碼來源:QueueReader.java

示例6: start

import javax.jms.MessageConsumer; //導入方法依賴的package包/類
@Override
public void start() throws Throwable {

	boolean durableSubscribers = false;// 持久化訂閱
	String clientID = null;
	if (ChannelType.Topic == queue.getType()) {
		// durableSubscribers = (Boolean) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_C_DURABLESUBSCRIBERS);
		durableSubscribers = queue.isDurableSubscribers();
		if (durableSubscribers) {
			// clientID = (String) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_C_CLIENTID);
			clientID = queue.getClientID();
			if (null == clientID) {
				throw new XMLParseException("durable subscribers is missing a clientID: " + queue.getName());
			}
		}
	}

	ActiveMqSource mqSource = (ActiveMqSource) MqContainer.getInstance().getMqSourceManager().getMqSource(queue.getMsKey());

	Connection connection = null;
	if (!durableSubscribers) {
		connection = mqSource.getConnection();
	} else {
		connection = mqSource.getConnection(clientID);
		this.durableSubscriberConn = connection;
	}

	// boolean transacted = (Boolean) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_C_TRANSACTED);
	// int acknowledgeMode = (Integer) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_C_ACKNOWLEDGEMODE);
	boolean transacted = queue.isTransacted();
	int acknowledgeMode = queue.getAcknowledgeMode();
	session = connection.createSession(transacted, acknowledgeMode);

	Destination destination = null;
	if (ChannelType.Queue == queue.getType()) {
		destination = session.createQueue(queue.getName());
		typeStr = "queue";
	} else if (ChannelType.Topic == queue.getType()) {
		destination = session.createTopic(queue.getName());
		typeStr = "topic";
	}

	MessageConsumer messageConsumer = null;
	if (!durableSubscribers) {
		messageConsumer = session.createConsumer(destination);
	} else {
		messageConsumer = session.createDurableSubscriber((Topic) destination, clientID);
	}

	running = true;

	// boolean asynReceiveMessages = (Boolean) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_C_ASYNRECEIVEMESSAGES);
	boolean asynReceiveMessages = queue.isAsynReceive();
	if (asynReceiveMessages) {
		messageConsumer.setMessageListener(new MessageListener() {
			@Override
			public void onMessage(Message message) {
				try {
					// TODO 如果是session.commit();, 是否需要使用同步關鍵字, 防止提交別的線程的東西
					// System.out.println("####################:" + Thread.currentThread().getName());
					processMessage(message);
				} catch (Throwable e) {
					log.error("listen to the [" + queue.getName() + "] error.", e);
				}
			}
		});
	} else {
		// long receiveTimeout = (Long) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_C_RECEIVETIMEOUT);
		long receiveTimeout = queue.getReceiveTimeout();
		startSyncReceiveThread(messageConsumer, receiveTimeout);
	}
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:73,代碼來源:ActiveMqReceiver.java


注:本文中的javax.jms.MessageConsumer.setMessageListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。