当前位置: 首页>>代码示例>>Java>>正文


Java MessageProducer.setDeliveryMode方法代码示例

本文整理汇总了Java中javax.jms.MessageProducer.setDeliveryMode方法的典型用法代码示例。如果您正苦于以下问题:Java MessageProducer.setDeliveryMode方法的具体用法?Java MessageProducer.setDeliveryMode怎么用?Java MessageProducer.setDeliveryMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.MessageProducer的用法示例。


在下文中一共展示了MessageProducer.setDeliveryMode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createMessageProducer

import javax.jms.MessageProducer; //导入方法依赖的package包/类
public static MessageProducer createMessageProducer(
    Session session,
    Destination destination,
    MessageProducerOption producerOption) throws JMSException {

  MessageProducer producer = session.createProducer(destination);
  producer.setDeliveryDelay(producerOption.getDeliveryDelay());
  producer.setDeliveryMode(producerOption.getDeliveryMode());
  producer.setDisableMessageTimestamp(producerOption.isDisableMessageTimestamp());
  producer.setDisableMessageID(producerOption.isDisableMessageId());
  producer.setPriority(producerOption.getPriority());
  producer.setTimeToLive(producerOption.getTimeToLive());

  return producer;

}
 
开发者ID:bighector,项目名称:-artemis-disruptor-miaosha,代码行数:17,代码来源:MessageProducerFactory.java

示例2: main

import javax.jms.MessageProducer; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {
            // Create a ConnectionFactory
            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");

            // Create a Connection
            Connection connection = connectionFactory.createConnection();
            connection.start();

            // Create a Session
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // Create the destination (Topic or Queue)
            Destination destination = session.createQueue("HELLOWORLD.TESTQ");

            // Create a MessageProducer from the Session to the Topic or Queue
            MessageProducer producer = session.createProducer(destination);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

            // Create a messages
            String text = "Hello world! From: " + Thread.currentThread().getName();
            TextMessage message = session.createTextMessage(text);

            // Tell the producer to send the message
            System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName());
            producer.send(message);

            // Clean up
            session.close();
            connection.close();
        }
        catch (Exception e) {
            System.out.println("Caught: " + e);
            e.printStackTrace();
        }
    
	}
 
开发者ID:Illusionist80,项目名称:SpringTutorial,代码行数:39,代码来源:HelloWorldProducer.java

示例3: run

import javax.jms.MessageProducer; //导入方法依赖的package包/类
public void run() {
    try {
        // Create a ConnectionFactory
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");

        // Create a Connection
        Connection connection = connectionFactory.createConnection();
        connection.start();

        // Create a Session
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        // Create the destination (Topic or Queue)
        Destination destination = session.createQueue("HELLOWORLD.TESTQ");

        // Create a MessageProducer from the Session to the Topic or Queue
        MessageProducer producer = session.createProducer(destination);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        // Create a messages
        String text = "Hello world! From: " + Thread.currentThread().getName() + " : " + this.hashCode();
        TextMessage message = session.createTextMessage(text);

        // Tell the producer to send the message
        System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName());
        producer.send(message);

        // Clean up
        session.close();
        connection.close();
    }
    catch (Exception e) {
        System.out.println("Caught: " + e);
        e.printStackTrace();
    }
}
 
开发者ID:Illusionist80,项目名称:SpringTutorial,代码行数:37,代码来源:HelloWorldProducerThread.java

示例4: sendAndReceive

import javax.jms.MessageProducer; //导入方法依赖的package包/类
@Test
public void sendAndReceive() throws Exception {
  Destination destination = session.createQueue("TEST.FOO");

  MessageProducer messageProducer = session.createProducer(destination);
  messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

  // Instrument MessageProducer with TracingMessageProducer
  TracingMessageProducer producer =
      new TracingMessageProducer(messageProducer, mockTracer);

  MessageConsumer messageConsumer = session.createConsumer(destination);

  // Instrument MessageConsumer with TracingMessageConsumer
  TracingMessageConsumer consumer = new TracingMessageConsumer(messageConsumer, mockTracer);

  TextMessage message = session.createTextMessage("Hello world");

  producer.send(message);

  TextMessage received = (TextMessage) consumer.receive(5000);
  assertEquals("Hello world", received.getText());

  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  assertEquals(2, mockSpans.size());

  checkSpans(mockSpans);
  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jms,代码行数:30,代码来源:TracingActiveMQTest.java

示例5: newMessageProducer

import javax.jms.MessageProducer; //导入方法依赖的package包/类
private MessageProducer newMessageProducer(String queueName) throws JMSException {
    // Create the session
    Destination destination = session.createQueue(queueName);
    // Create the producer.
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    logger.info("Created message producer for queue " + queueName);
    return producer;
}
 
开发者ID:oneops,项目名称:oneops,代码行数:10,代码来源:InductorPublisher.java

示例6: sendMessage

import javax.jms.MessageProducer; //导入方法依赖的package包/类
public void sendMessage(Message message) throws JMSException {
	Connection connection = null;
	try {
		connection = startConnection(); //try to be smarter here and initiate start connection
		Session session = null;
		try {
			session = connection.createSession(isTransacted, Session.AUTO_ACKNOWLEDGE);
			Destination dest;
			if (isQueue) {
				dest = session.createQueue(destinationName);
			} else {
				dest = session.createTopic(destinationName);
			}
			MessageProducer producer = session.createProducer(dest);
			try {

				if (isPersistant) producer.setDeliveryMode(DeliveryMode.PERSISTENT);
				if (timeToLive > 0) producer.setTimeToLive(timeToLive);

				producer.send(message);
			} finally {
				if (producer != null) producer.close();
			}
		} finally {
			if (session != null) session.close();
		}
	} finally {
		safeCloseConnection(connection);
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:31,代码来源:JmsClient.java

示例7: createConnectionAndSendMessage

import javax.jms.MessageProducer; //导入方法依赖的package包/类
public void createConnectionAndSendMessage(String ipAddress) throws JMSException {

		Connection connection = connectionFactory.createConnection();
		connection.start();

		Session topicSession = connection.createSession(false, AUTO_ACKNOWLEDGE);

		MessageProducer producer = topicSession.createProducer(topic);
		producer.setDeliveryMode(PERSISTENT);

		ObjectMessage message = topicSession.createObjectMessage();

		BUSStop busStop = new BUSStop();
		busStop.setName("Rome");

		message.setStringProperty("s_id", "Sample");
		message.setObject((Serializable) busStop);

		producer.send(message);
		logger.info("message sent successfully");
	}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:22,代码来源:Publisher.java

示例8: testGetDevicesUsingString

import javax.jms.MessageProducer; //导入方法依赖的package包/类
public void testGetDevicesUsingString() throws Exception {

		final ResponseConfiguration responseConfiguration = new ResponseConfiguration(ResponseType.ONE, 1000, TimeUnit.MILLISECONDS);

		final List<DeviceRequest> responses = new ArrayList<>(1);

        final ISubscriber<IBeanListener<DeviceRequest>>  receive = eservice.createSubscriber(uri, EventConstants.DEVICE_RESPONSE_TOPIC);
		// Just listen to our id changing.
		receive.addListener("726c5d29-72f8-42e3-ba0c-51d26378065e", new IBeanListener<DeviceRequest>() {
			@Override
			public void beanChangePerformed(BeanEvent<DeviceRequest> evt) {
				responses.add(evt.getBean());
				responseConfiguration.countDown();
			}
		});

		// Manually send a string without the extra java things...
		final String rawString = "{\"uniqueId\":\"726c5d29-72f8-42e3-ba0c-51d26378065e\",\"deviceType\":\"RUNNABLE\",\"configure\":false}";

		MessageProducer producer = null;
		Connection      send     = null;
		Session         session  = null;

		try {

			QueueConnectionFactory connectionFactory = (QueueConnectionFactory)eservice.getEventConnectorService().createConnectionFactory(uri);
			send              = connectionFactory.createConnection();

			session = send.createSession(false, Session.AUTO_ACKNOWLEDGE);
			Topic topic = session.createTopic(EventConstants.DEVICE_REQUEST_TOPIC);

			producer = session.createProducer(topic);
			producer.setDeliveryMode(DeliveryMode.PERSISTENT);

			// Send the request
			producer.send(session.createTextMessage(rawString));

		} finally {
			try {
				if (session!=null) session.close();
			} catch (JMSException e) {
				throw new EventException("Cannot close session!", e);
			}
		}

		responseConfiguration.latch(null); // Wait or die trying

		if (responses.isEmpty()) throw new Exception("There was no response identified!");
		if (responses.get(0).getDevices().size()<1) throw new Exception("There were no devices found and at least the mandelbrot example should have been!");

	}
 
开发者ID:eclipse,项目名称:scanning,代码行数:52,代码来源:DeviceRequestTest.java


注:本文中的javax.jms.MessageProducer.setDeliveryMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。