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