当前位置: 首页>>代码示例>>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;未经允许,请勿转载。