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


Java Session.createProducer方法代碼示例

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


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

示例1: main

import javax.jms.Session; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
   Connection connection = null;
   String csvData = System.getProperty(CSVDATA);
   if(CSVDATA == null || CSVDATA.equals(""))
       throw new RuntimeException("LoyaltyCardManager.main() must pass the "+CSVDATA +" system property With format  OPERATION;USERID;FIRSTNAME;LASTNAME;TRXID;TRXFEESAMOUNT;CURRENCY");
   System.out.println("LoyaltyCardManager() will connect to router: "+ROUTER_URL+" : at the following address: "+QUEUE_NAME);
   ConnectionFactory connectionFactory = new JmsConnectionFactory(ROUTER_URL);
   try {
      // Step 1. Create an AMQP qpid connection
      connection = connectionFactory.createConnection();
      // Step 2. Create a JMS session
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      // Step 3. Create a Producer
      Queue fidelityRequestQueue = session.createQueue(QUEUE_NAME);
      MessageProducer beosbankFidelityRequestProducer = session.createProducer(fidelityRequestQueue);
      // Step 4. send a CSV Text Data on user transactions 
      beosbankFidelityRequestProducer.send(session.createTextMessage(csvData));
      System.out.println("\nmessage sent:"+ csvData+" \n");
   } finally {
      if (connection != null) {
         // Step 9. close the connection
         connection.close();
      }
   }
}
 
開發者ID:PacktPublishing,項目名稱:JBoss-Developers-Guide,代碼行數:26,代碼來源:LoyaltyCardManager.java

示例2: sendMessages

import javax.jms.Session; //導入方法依賴的package包/類
public void sendMessages(ConnectionFactory connectionFactory) throws Exception {
    for (int i = 0; i < NUM_MESSAGES; i++) {
        Connection connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue(QUEUE);
        MessageProducer producer = session.createProducer(destination);

        String msgTo = "hello";
        TextMessage message = session.createTextMessage(msgTo);
        producer.send(message);
        connection.close();
        LOG.debug("sent " + i + " messages using " + connectionFactory.getClass());
    }
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:17,代碼來源:PooledSessionExhaustionTest.java

示例3: putQueue

import javax.jms.Session; //導入方法依賴的package包/類
private void putQueue(List<String> events) throws Exception {
  ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
      PASSWORD, BROKER_BIND_URL);
  Connection connection = factory.createConnection();
  connection.start();

  Session session = connection.createSession(true,
      Session.AUTO_ACKNOWLEDGE);
  Destination destination = session.createQueue(DESTINATION_NAME);
  MessageProducer producer = session.createProducer(destination);

  for (String event : events) {
    TextMessage message = session.createTextMessage();
    message.setText(event);
    producer.send(message);
  }
  session.commit();
  session.close();
  connection.close();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:21,代碼來源:TestIntegrationActiveMQ.java

示例4: sendWithReplyToTemp

import javax.jms.Session; //導入方法依賴的package包/類
private void sendWithReplyToTemp(ConnectionFactory cf, String serviceQueue) throws JMSException, InterruptedException {
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQueue = session.createTemporaryQueue();
    TextMessage msg = session.createTextMessage("Request");
    msg.setJMSReplyTo(tempQueue);
    MessageProducer producer = session.createProducer(session.createQueue(serviceQueue));
    producer.send(msg);

    MessageConsumer consumer = session.createConsumer(tempQueue);
    Message replyMsg = consumer.receive();
    assertNotNull(replyMsg);

    LOG.debug("Reply message: {}", replyMsg);

    consumer.close();

    producer.close();
    session.close();
    connection.close();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:23,代碼來源:PooledConnectionTempQueueTest.java

示例5: testToString

import javax.jms.Session; //導入方法依賴的package包/類
@Test
public void testToString() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    Session session = connection.createSession();
    Queue queue = session.createTemporaryQueue();
    MessageProducer producer = session.createProducer(queue);

    assertNotNull(producer.toString());
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:10,代碼來源:JmsPoolMessageProducerTest.java

示例6: run

import javax.jms.Session; //導入方法依賴的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

示例7: testNullDestinationOnSendToAnonymousProducer

import javax.jms.Session; //導入方法依賴的package包/類
@Test
public void testNullDestinationOnSendToAnonymousProducer() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    Session session = connection.createSession();
    MessageProducer producer = session.createProducer(null);

    try {
        producer.send(null, session.createMessage());
        fail("Should not be able to send with null destination");
    } catch (InvalidDestinationException ide) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:12,代碼來源:JmsPoolMessageProducerTest.java

示例8: validateFactoryCreationWithActiveMQLibraries

import javax.jms.Session; //導入方法依賴的package包/類
/**
 * This test simply validates that {@link ConnectionFactory} can be setup by pointing to the location of the client
 * libraries at runtime. It uses ActiveMQ which is not present at the POM but instead pulled from Maven repo using
 * {@link TestUtils#setupActiveMqLibForTesting(boolean)}, which implies that for this test to run the computer must
 * be connected to the Internet. If computer is not connected to the Internet, this test will quietly fail logging a
 * message.
 */
@Test
public void validateFactoryCreationWithActiveMQLibraries() throws Exception {
    try {
        String libPath = TestUtils.setupActiveMqLibForTesting(true);

        TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
        JNDIConnectionFactoryProvider cfProvider = new JNDIConnectionFactoryProvider();
        runner.addControllerService("cfProvider", cfProvider);
        runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.BROKER_URI,
                "vm://localhost?broker.persistent=false");
        runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.JNDI_CF_LOOKUP, "ConnectionFactory");
        runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, libPath);
        runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
                "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        runner.enableControllerService(cfProvider);
        runner.assertValid(cfProvider);

        Connection connection = cfProvider.getConnectionFactory().createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination queue = session.createQueue("myqueue");
        MessageProducer producer = session.createProducer(queue);
        MessageConsumer consumer = session.createConsumer(queue);

        TextMessage message = session.createTextMessage("Hello");
        producer.send(message);
        assertEquals("Hello", ((TextMessage) consumer.receive()).getText());
        connection.stop();
        connection.close();
    } catch (Exception e) {
        logger.error("'validateFactoryCreationWithActiveMQLibraries' failed due to ", e);
    }
}
 
開發者ID:SolaceLabs,項目名稱:solace-integration-guides,代碼行數:42,代碼來源:JNDIConnectionFactoryProviderTest.java

示例9: main

import javax.jms.Session; //導入方法依賴的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

示例10: testMessageProducersAreUnique

import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testMessageProducersAreUnique() throws Exception {
    JmsPoolConnection connection = (JmsPoolConnection) pooledFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    Queue queue1 = session.createTemporaryQueue();
    Queue queue2 = session.createTemporaryQueue();

    JmsPoolMessageProducer producer1 = (JmsPoolMessageProducer) session.createProducer(queue1);
    JmsPoolMessageProducer producer2 = (JmsPoolMessageProducer) session.createProducer(queue2);

    assertNotSame(producer1.getMessageProducer(), producer2.getMessageProducer());
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:14,代碼來源:PooledSessionNoPublisherCachingTest.java

示例11: queueMessage

import javax.jms.Session; //導入方法依賴的package包/類
static void queueMessage(Session session, String text, String queueName) {
    try {
        Queue queue = session.createQueue(queueName);
        MessageProducer producer = session.createProducer(queue);

        TextMessage message = session.createTextMessage(text);
        message.setJMSCorrelationID(MDC.get(X_OBOS_REQUEST_ID));

        producer.send(message);
        session.commit();
    } catch (JMSException ex) {
        throw new MessageQueueException("Could not queue message '" + text + "'", ex);
    }
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:15,代碼來源:ActiveMqUtils.java

示例12: testMessageProducersAreAllTheSame

import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testMessageProducersAreAllTheSame() throws Exception {
    JmsPoolConnection connection = (JmsPoolConnection) pooledFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    Queue queue1 = session.createTemporaryQueue();
    Queue queue2 = session.createTemporaryQueue();

    JmsPoolMessageProducer producer1 = (JmsPoolMessageProducer) session.createProducer(queue1);
    JmsPoolMessageProducer producer2 = (JmsPoolMessageProducer) session.createProducer(queue2);

    assertSame(producer1.getMessageProducer(), producer2.getMessageProducer());

    connection.close();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:16,代碼來源:PooledSessionTest.java

示例13: testConsumerProducerWithSsl

import javax.jms.Session; //導入方法依賴的package包/類
@Parameters({ "broker-ssl-port"})
@Test
public void testConsumerProducerWithSsl(String port) throws Exception {
    String queueName = "testConsumerProducerWithAutoAck";
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder("admin", "admin", "localhost", port)
            .enableSsl()
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // publish 100 messages
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);

    int numberOfMessages = 100;
    for (int i = 0; i < numberOfMessages; i++) {
        producer.send(producerSession.createTextMessage("Test message " + i));
    }
    producerSession.close();

    // Consume published messages
    Session subscriberSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

    for (int i = 0; i < numberOfMessages; i++) {
        Message message = consumer.receive(1000);
        Assert.assertNotNull(message, "Message #" + i + " was not received");
    }

    connection.close();
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:39,代碼來源:SslTransportTest.java

示例14: sendMessage

import javax.jms.Session; //導入方法依賴的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

示例15: doPublish

import javax.jms.Session; //導入方法依賴的package包/類
protected void doPublish(Event event) throws EdsException {
  Connection conn = null;
  Session session = null;
  MessageProducer messageProducer = null;
  try {
    LOG.debug("eds pub 3 mq in -[event:" + event + "]");
    conn = connectionFactory.createConnection();
    // 設置非事務,客戶端確認方式
    session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);

    MapMessage mapMessage = session.createMapMessage();
    mapMessage = EventConverter.convertToMessage(mapMessage, event);
    Destination dest = getDestination(event.getName(), session);
    messageProducer = session.createProducer(dest);
    messageProducer.send(mapMessage);
    // commit session if necessary
    if (session.getTransacted()) {
      session.commit();
    }
    LOG.debug("eds pub 4 mq ok -[conn:" + conn + ",session:" + session + ",event:" + event + "]");
  }catch(JMSException e){
    throw new EdsException("eds client activemq doPublish exception ", e);
  }finally {
    releaseSession(session);
    releaseMessageProducer(messageProducer);
    releaseConnection(conn, false);
  }
}
 
開發者ID:eXcellme,項目名稱:eds,代碼行數:29,代碼來源:ActiveMQEventPublisher.java


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