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


Java Session.createTextMessage方法代碼示例

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


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

示例1: putTopic

import javax.jms.Session; //導入方法依賴的package包/類
private void putTopic(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.createTopic(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

示例2: receiveAndRespondWithMessageIdAsCorrelationId

import javax.jms.Session; //導入方法依賴的package包/類
public void receiveAndRespondWithMessageIdAsCorrelationId(ConnectionFactory connectionFactory, String queueName) throws JMSException {
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(session.createQueue(queueName));
    final javax.jms.Message inMessage = consumer.receive();

    String requestMessageId = inMessage.getJMSMessageID();
    LOG.debug("Received message " + requestMessageId);
    final TextMessage replyMessage = session.createTextMessage("Result");
    replyMessage.setJMSCorrelationID(inMessage.getJMSMessageID());
    final MessageProducer producer = session.createProducer(inMessage.getJMSReplyTo());
    LOG.debug("Sending reply to " + inMessage.getJMSReplyTo());
    producer.send(replyMessage);

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

示例3: 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

示例4: publiceerMaakSelectieGeenResultaatNetwerkTaak

import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void publiceerMaakSelectieGeenResultaatNetwerkTaak(List<MaakSelectieResultaatTaak> maakSelectieGeenResultaatNetwerkTaken) {
    LOGGER.info("publiceer maak selectie resultaat taken");
    final ProducerCallback<Void> producerCallback = (final Session session, final MessageProducer producer) -> {
        LOGGER.debug("publiceer maak selectie resultaat taak");
        for (final MaakSelectieResultaatTaak maakSelectieGeenResultaatNetwerkTaak : maakSelectieGeenResultaatNetwerkTaken) {
            final String
                    groupId =
                    maakSelectieGeenResultaatNetwerkTaak.getSelectieRunId() + "_" + maakSelectieGeenResultaatNetwerkTaak
                            .getToegangLeveringsAutorisatieId()
                            + "_"
                            + maakSelectieGeenResultaatNetwerkTaak.getDienstId();
            final Message message = session.createTextMessage(serializer.serialiseerNaarString(maakSelectieGeenResultaatNetwerkTaak));
            message.setStringProperty(LeveringConstanten.JMS_MESSAGEGROUP_HEADER, groupId);
            producer.send(message);
        }
        return null;
    };
    PublicatieHelper.publiceer(maakSelectieGeenResultaatNetwerkTemplate, producerCallback,
            () -> "fout in verzenden berichten naar maak selectie geen resultaat netwerk taak queue");
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:22,代碼來源:MaakSelectieResultaatTaakPublicatieServiceImpl.java

示例5: doSendTextMessage

import javax.jms.Session; //導入方法依賴的package包/類
private void doSendTextMessage( final Session session, final Destination destination,
                                final String textMessage,
                                final Map<String, ?> properties ) throws JMSException {

    try {
        final Message message = textMessage != null
                                                    ? session.createTextMessage(textMessage)
                                                    : session.createTextMessage();
        if (properties != null) {
            // Note: Setting any properties (including JMS fields) using
            // setObjectProperty might not be supported by all providers
            // Tested with: ActiveMQ
            for (final Entry<String, ?> property : properties.entrySet()) {
                message.setObjectProperty(property.getKey(), property.getValue());
            }
        }
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
    } finally {
        releaseSession(false);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:23,代碼來源:JmsClient.java

示例6: 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));
        JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
        runner.addControllerService("cfProvider", cfProvider);
        runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI,
                "vm://localhost?broker.persistent=false");
        runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, libPath);
        runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
                "org.apache.activemq.ActiveMQConnectionFactory");
        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,代碼行數:43,代碼來源:JMSConnectionFactoryProviderTest.java

示例7: 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

示例8: createMessage

import javax.jms.Session; //導入方法依賴的package包/類
public Message createMessage(Object messageObject) throws JMSException {
	Connection connection = null;
	Message result = null;
	try {
		connection = startConnection();
		Session session = null;
		try {
			session = connection.createSession(isTransacted, Session.AUTO_ACKNOWLEDGE);
			if (messageObject == null) {
				result = session.createMessage();
			} else {
				if (messageObject instanceof String) {
					result = session.createTextMessage((String) messageObject);
				} else {
					result = session.createObjectMessage((Serializable) messageObject);
				}
			}
		} finally {
			if (session != null) session.close();
		}
	} finally {
		safeCloseConnection(connection);
	}
	return result;
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:26,代碼來源:JmsClient.java

示例9: handleMessage

import javax.jms.Session; //導入方法依賴的package包/類
private void handleMessage(MessageHandler handler, Message message, Session session) {
    if (! (message instanceof TextMessage)) {
        return;
    }
    TextMessage textMessage = (TextMessage) message;
    String text = null;
    String requestId = UUID.randomUUID().toString();
    try {
        text = textMessage.getText();
        if (StringUtils.isNotEmpty(message.getJMSCorrelationID())) {
            requestId = message.getJMSCorrelationID();
        }

        MDC.put(X_OBOS_REQUEST_ID, requestId);

        log.info("Received message '{}'", text);

        handler.handle(new ObjectMapper().readTree(text));
    } catch (Exception e) {
        log.error("Failed to process message", e);
        try {
            TextMessage errorMessage = session.createTextMessage(text);
            errorMessage.setJMSCorrelationID(requestId);

            Queue queue = session.createQueue(queueError);
            MessageProducer errorProducer = session.createProducer(queue);
            errorProducer.send(errorMessage);
        } catch (JMSException jmse) {
            log.error("Failed to create error message", jmse);
        }
    } finally {
        MDC.remove(X_OBOS_REQUEST_ID);
    }
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:35,代碼來源:ActiveMqListener.java

示例10: publiceerSchrijfTaken

import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void publiceerSchrijfTaken(List<SelectieFragmentSchrijfBericht> schrijfTaken) {
    LOGGER.info("publiceer selectie schrijf taken");
    final ProducerCallback<Void> producerCallback = (final Session session, final MessageProducer producer) -> {
        for (final SelectieFragmentSchrijfBericht selectieTaak : schrijfTaken) {
            LOGGER.debug("publiceer selectie schrijf taak");
            final Message message = session.createTextMessage(serializer.serialiseerNaarString(selectieTaak));
            message.setStringProperty(LeveringConstanten.JMS_MESSAGEGROUP_HEADER, String.valueOf(selectieTaak.getSelectietaakId()));
            producer.send(message);
        }
        return null;
    };
    publiceer(selectieTaakJmsTemplate, producerCallback,
            () -> "fout in verzenden berichten naar selectie schrijf taak queue");
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:16,代碼來源:SelectieSchrijfTaakPublicatieServiceImpl.java

示例11: publiceerSelectieTaak

import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void publiceerSelectieTaak(final List<SelectieVerwerkTaakBericht> selectieTaken) {
    final ProducerCallback<Void> producerCallback = (final Session session, final MessageProducer producer) -> {
        for (final SelectieVerwerkTaakBericht selectieTaak : selectieTaken) {
            final Message message = session.createTextMessage(serializer.serialiseerNaarString(selectieTaak));
            producer.send(message);
        }
        return null;
    };
    publiceer(selectieTaakJmsTemplate, producerCallback, () -> "fout in verzenden berichten naar selectie taak queue");
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:12,代碼來源:SelectieTaakPublicatieServiceImpl.java

示例12: requeueFailedMessages

import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void requeueFailedMessages() {
    try {
        ActiveMQConnection connection = ActiveMqUtils.openConnection(user, password, url);
        Session session = ActiveMqUtils.startSession(connection);

        int count = getQueueSize(session, queueError);

        if (count < 1) {
            return;
        }

        log.info("Requeuing {} failed messages...", count);

        Queue queueErr = session.createQueue(queueError);
        MessageConsumer consumer = session.createConsumer(queueErr);

        Queue queueRetry = session.createQueue(queueInput);
        MessageProducer producer = session.createProducer(queueRetry);

        for (int consumed = 0; consumed < count; consumed++) {
            TextMessage message = (TextMessage) consumer.receive(REQUEUE_TIMEOUT);

            if (message == null) {
                continue;
            }

            String text = message.getText();
            String requestId = message.getJMSCorrelationID();

            log.info("Requeuing message '{}'", text);

            try {
                TextMessage newMessage = session.createTextMessage(text);
                newMessage.setJMSCorrelationID(requestId);

                producer.send(newMessage);
            } catch (Exception e) {
                log.error("Failed to requeue message", e);
            }

            message.acknowledge();
            session.commit();
        }

        producer.close();
        consumer.close();
    } catch (JMSException ex) {
        throw new MessageQueueException("Failed to requeue failed messages", ex);
    }
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:52,代碼來源:ActiveMqListener.java

示例13: 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

示例14: 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

示例15: publiceerSelectieTaakResultaat

import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void publiceerSelectieTaakResultaat(final SelectieTaakResultaat selectieTaakResultaat) {
    final ProducerCallback<Void> producerCallback = (final Session session, final MessageProducer producer) -> {
        final Message message = session.createTextMessage(serializer.serialiseerNaarString(selectieTaakResultaat));
        producer.send(message);
        return null;
    };
    publiceer(selectieTaakResultaatJmsTemplate, producerCallback, () -> "fout in verzenden berichten naar selectie taak resultaat queue");
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:10,代碼來源:SelectieTaakResultaatPublicatieServiceImpl.java


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