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


Java TextMessage類代碼示例

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


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

示例1: receiveAndRespondWithMessageIdAsCorrelationId

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

示例2: publishCiStateMessage

import javax.jms.TextMessage; //導入依賴的package包/類
/**
   * Publish ci state message.
   *
   * @param event the event
   */
  public void publishCiStateMessage(CiChangeStateEvent event) {
  	
try {
	TextMessage message = session.createTextMessage(gson.toJson(event));
   	message.setLongProperty("ciId", event.getCiId());
   	message.setStringProperty("type", "ci-change-state");
   	message.setStringProperty("ciState", event.getNewState());
   	producer.send(message);
   	logger.info("Published: ciId:" + event.getCiId());
   	logger.info(message.getText());
} catch (JMSException e) {
	// TODO see if we can put some durability here
	logger.error("caught Exception publishing",e);
}
  	
  }
 
開發者ID:oneops,項目名稱:oneops,代碼行數:22,代碼來源:OpsEventPublisher.java

示例3: generateMessages

import javax.jms.TextMessage; //導入依賴的package包/類
/**
 * Generates JMS messages
 */
@PostConstruct
public void generateMessages() throws JMSException {
    for (int i = 0; i < messageCount; i++) {
        final int index = i;
        final String text = "Message number is " + i + ".";

        template.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage(text);
                message.setIntProperty(MESSAGE_COUNT, index);
                
                System.out.println("Sending message: " + text);
                
                return message;
            }
        });
    }
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:22,代碼來源:JmsMessageProducer.java

示例4: toSourceRecord

import javax.jms.TextMessage; //導入依賴的package包/類
/**
 * Convert a message into a Kafka Connect SourceRecord.
 * 
 * @param context            the JMS context to use for building messages
 * @param topic              the Kafka topic
 * @param messageBodyJms     whether to interpret MQ messages as JMS messages
 * @param message            the message
 * 
 * @return the Kafka Connect SourceRecord
 * 
 * @throws JMSException      Message could not be converted
 */
@Override public SourceRecord toSourceRecord(JMSContext context, String topic, boolean messageBodyJms, Message message) throws JMSException {
    byte[] payload;
    if (message instanceof BytesMessage) {
        payload = message.getBody(byte[].class);
    }
    else if (message instanceof TextMessage) {
        String s = message.getBody(String.class);
        payload = s.getBytes(UTF_8);
    }
    else {
        log.error("Unsupported JMS message type {}", message.getClass());
        throw new ConnectException("Unsupported JMS message type");
    }

    SchemaAndValue sv = converter.toConnectData(topic, payload);
    return new SourceRecord(null, null, topic, sv.schema(), sv.value());
}
 
開發者ID:ibm-messaging,項目名稱:kafka-connect-mq-source,代碼行數:30,代碼來源:JsonRecordBuilder.java

示例5: onMessage

import javax.jms.TextMessage; //導入依賴的package包/類
@Override
public void onMessage(final Message message) {
    // 使用線程池多線程處理
    threadPoolTaskExecutor.execute(new Runnable() {
        @Override
        public void run() {
            TextMessage textMessage = (TextMessage) message;
            try {
                String text = textMessage.getText();
                LOGGER.info("消費:{}", text);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
開發者ID:ChangyiHuang,項目名稱:shuzheng,代碼行數:17,代碼來源:DefaultMessageQueueListener.java

示例6: msgDeployment

import javax.jms.TextMessage; //導入依賴的package包/類
@Test 
public void msgDeployment() throws Exception{
	TextMessage message = mock(TextMessage.class);
	when(message.getStringProperty("source")).thenReturn("deployment");
	String msgJson = gson.toJson(createCmsDeployment("active"));
	when(message.getText()).thenReturn(msgJson);

	listener.onMessage(message);
	//once more to get a SKIP
	when(message.getText()).thenReturn(gson.toJson(createCmsDeployment("is-not-active")));	
	listener.onMessage(message);
	
	listener.cleanup();

	listener.getConnectionStats();
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:17,代碼來源:CmsListenerTest.java

示例7: sendMessages

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

示例8: sendWithReplyToTemp

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

示例9: send

import javax.jms.TextMessage; //導入依賴的package包/類
private void send(Object task, String queue, Status status, String reason, String detail) {
    jmsTemplate.send(queue, (Session session) -> {
        TextMessage message = session.createTextMessage();
        message.setText(taskMapper.map(task));

        if (!Strings.isNullOrEmpty(header)) {
            setStringProperty(message, header, ExternalTaskManager.toTaskName(task.getClass()));
        }

        if (status != null) {
            setStringProperty(message, Headers.STATUS, status.name());
        }

        if (!Strings.isNullOrEmpty(reason)) {
            setStringProperty(message, Headers.REASON, reason);
        }

        if (!Strings.isNullOrEmpty(detail)) {
            setStringProperty(message, Headers.DETAIL, detail);
        }

        return message;
    });
}
 
開發者ID:EsikAntony,項目名稱:camunda-task-dispatcher,代碼行數:25,代碼來源:JmsExternalTaskSender.java

示例10: run

import javax.jms.TextMessage; //導入依賴的package包/類
@Override
public void run(String... strings) throws Exception {
    final String messageText = "Request";
    LOG.info("============= Sending: " + messageText);
    this.jmsTemplate.send("example", new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            Queue replyQueue = session.createQueue("reply-queue");

            TextMessage message = session.createTextMessage(messageText);

            message.setJMSCorrelationID(correlationID.toString());
            message.setJMSReplyTo(replyQueue);

            return message;
        }
    });
}
 
開發者ID:amqphub,項目名稱:amqp-10-jms-spring-boot,代碼行數:20,代碼來源:Requestor.java

示例11: publish

import javax.jms.TextMessage; //導入依賴的package包/類
/**
 * @param topicConnection
 * @param chatTopic
 * @param userId
 * @throws JMSException
 * @throws IOException
 */
void publish(TopicConnection topicConnection, Topic chatTopic, String userId)
		throws JMSException, IOException {
	TopicSession tsession = topicConnection.createTopicSession(false,
			Session.AUTO_ACKNOWLEDGE);
	TopicPublisher topicPublisher = tsession.createPublisher(chatTopic);
	topicConnection.start();
	
	BufferedReader reader = new BufferedReader(new InputStreamReader(
			System.in));
	while (true) {
		String msgToSend = reader.readLine();
		if (msgToSend.equalsIgnoreCase("exit")) {
			topicConnection.close();
			System.exit(0);
		} else {

			TextMessage msg = (TextMessage) tsession.createTextMessage();
			msg.setText("\n["+userId + " : " + msgToSend+"]");
			topicPublisher.publish(msg);
		}
	}
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:30,代碼來源:BasicJMSChat.java

示例12: startConsumer

import javax.jms.TextMessage; //導入依賴的package包/類
private void startConsumer() {
    try {
        connection = connectionFactory.createConnection();
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination;
        if ("topic".equalsIgnoreCase(destinationType)) {
            destination = session.createTopic(destinationName);
        } else {
            destination = session.createQueue(destinationName);
        }

        consumer = session.createConsumer(destination);
        isStarted.compareAndSet(false, true);
        while (true) {
            Message message = consumer.receive();

            if (message instanceof TextMessage) {
                TextMessage textMessage = (TextMessage) message;
                String text = textMessage.getText();
                if (isRecording.get()) {
                    addData(message, text);
                }
                counter.incrementAndGet();
            }
        }

    } catch (Exception e) {
        //e.printStackTrace();
    } finally {
        terminate();
    }
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:34,代碼來源:JMSConsumer.java

示例13: onMessage

import javax.jms.TextMessage; //導入依賴的package包/類
/**
 * Implementation of <code>MessageListener</code>.
 */
public void onMessage(Message message) {
    try {   
        int messageCount = message.getIntProperty(JmsMessageProducer.MESSAGE_COUNT);
        
        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage)message;
            String msg = tm.getText();
            
            
            System.out.println("Processed message '{}'.  value={}"+ msg+ messageCount);
            
            counter.incrementAndGet();
        }
    } catch (JMSException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:21,代碼來源:JmsMessageListener.java

示例14: testQueueOperations

import javax.jms.TextMessage; //導入依賴的package包/類
@Test
public void testQueueOperations() throws Exception {
    String queueName = "DEMO.TEST";
    QueueUtils.send(queueName, "first", 0);
    QueueConsumer consumer = new QueueConsumer(queueName);
    String text = consumer.waitForNextMessage();
    assertEquals("first", text);
    QueueUtils.send(queueName, "second", 0);
    QueueUtils.send(queueName, "third", 0);
    consumer.purgeMessages();
    QueueUtils.send(queueName, "foo", 25);
    consumer.setMessageListener(m -> {
        TextMessage tm = (TextMessage) m;
        try {
            logger.info("*** received message: {}", tm.getText());
            assertEquals("foo", tm.getText());
            passed = true;
            consumer.stop();
        } catch (JMSException e) {
            throw new RuntimeException(e);
        }

    });
    QueueUtils.waitUntilStopped();
    assertTrue(passed);
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:27,代碼來源:QueueUtilsTest.java

示例15: setUp

import javax.jms.TextMessage; //導入依賴的package包/類
@BeforeEach
public void setUp() throws JMSException {
    initMocks(this);
    when(mockEvent.getTarget()).thenReturn(of(rdf.createIRI("trellis:repository/resource")));
    when(mockEvent.getAgents()).thenReturn(singleton(Trellis.AdministratorAgent));
    when(mockEvent.getCreated()).thenReturn(time);
    when(mockEvent.getIdentifier()).thenReturn(rdf.createIRI("urn:test"));
    when(mockEvent.getTypes()).thenReturn(singleton(AS.Update));
    when(mockEvent.getTargetTypes()).thenReturn(singleton(LDP.RDFSource));
    when(mockEvent.getInbox()).thenReturn(empty());

    when(mockConnection.createSession(anyBoolean(), eq(AUTO_ACKNOWLEDGE))).thenReturn(mockSession);
    when(mockSession.createQueue(eq(queueName))).thenReturn(mockQueue);
    when(mockSession.createTextMessage(anyString())).thenReturn(mockMessage);
    when(mockSession.createProducer(any(Queue.class))).thenReturn(mockProducer);

    doNothing().when(mockProducer).send(any(TextMessage.class));
}
 
開發者ID:trellis-ldp,項目名稱:trellis-jms,代碼行數:19,代碼來源:JmsPublisherTest.java


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