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


Java BytesMessage类代码示例

本文整理汇总了Java中javax.jms.BytesMessage的典型用法代码示例。如果您正苦于以下问题:Java BytesMessage类的具体用法?Java BytesMessage怎么用?Java BytesMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: onMessage

import javax.jms.BytesMessage; //导入依赖的package包/类
@Override
public void onMessage(Message message) {

  try {

    if (message instanceof BytesMessage) {

      BytesMessage bytesMessage = (BytesMessage) message;
      byte[] data = new byte[(int) bytesMessage.getBodyLength()];
      bytesMessage.readBytes(data);
      LOG.info("Message received {}", new String(data));

    } else if (message instanceof TextMessage) {

      TextMessage textMessage = (TextMessage) message;
      String text = textMessage.getText();
      LOG.info("Message received {}", text);
    }

  } catch (JMSException jmsEx) {
    jmsEx.printStackTrace();
  }
}
 
开发者ID:ppatierno,项目名称:amqp-kafka-demo,代码行数:24,代码来源:Receiver.java

示例2: validateBytesConvertedToBytesMessageOnSend

import javax.jms.BytesMessage; //导入依赖的package包/类
@Test
public void validateBytesConvertedToBytesMessageOnSend() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    publisher.publish(destinationName, "hellomq".getBytes());

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    byte[] bytes = new byte[7];
    ((BytesMessage) receivedMessage).readBytes(bytes);
    assertEquals("hellomq", new String(bytes));

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:17,代码来源:JMSPublisherConsumerTest.java

示例3: toSourceRecord

import javax.jms.BytesMessage; //导入依赖的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

示例4: client_sends_five_messages_to_queue_and_receives

import javax.jms.BytesMessage; //导入依赖的package包/类
@Test
public void client_sends_five_messages_to_queue_and_receives() throws Exception {
    try (JMSClient client = server.createClient()) {
        DummyListener listener = new DummyListener(5);
        client.addQueueListener(DUMMY_QUEUE, listener);
        client.startListening();

        for (int i = 0; i < 5; i++) {
            client.sendToQueue(DUMMY_QUEUE, i + "");
        }

        List<BytesMessage> bytesMessages = listener.awaitMessages();
        assertThat(bytesMessages.size(), is(5));
        assertNotNull(bytesMessages.get(0));

        // Ensure messages are received in the same order they were sent
        for (int i = 0; i < 5; i++) {
            assertThat(JMSHelper.objectFromMsg(bytesMessages.get(i)), is(i + ""));
        }
    }
}
 
开发者ID:florentw,项目名称:bench,代码行数:22,代码来源:JMSClientServerTest.java

示例5: client_sends_to_topic_and_receives

import javax.jms.BytesMessage; //导入依赖的package包/类
@Test
public void client_sends_to_topic_and_receives() throws Exception {
    DummyListener listener = new DummyListener(1);
    try (JMSClient client = server.createClient()) {

        server.getServer().createTopic(DUMMY_TOPIC);

        client.addTopicListener(DUMMY_TOPIC, listener);
        client.startListening();

        client.sendToTopic(DUMMY_TOPIC, DUMMY_PAYLOAD);

        List<BytesMessage> bytesMessages = listener.awaitMessages();
        assertReceivedMessageIs(bytesMessages, DUMMY_PAYLOAD);
    }
}
 
开发者ID:florentw,项目名称:bench,代码行数:17,代码来源:JMSClientServerTest.java

示例6: client_sends_five_messages_to_topic_and_receives

import javax.jms.BytesMessage; //导入依赖的package包/类
@Test
public void client_sends_five_messages_to_topic_and_receives() throws Exception {
    DummyListener listener = new DummyListener(5);
    try (JMSClient client = server.createClient()) {

        server.getServer().createTopic(DUMMY_TOPIC);
        client.addTopicListener(DUMMY_TOPIC, listener);
        client.startListening();

        for (int i = 0; i < 5; i++) {
            client.sendToTopic(DUMMY_TOPIC, i + "");
        }

        List<BytesMessage> bytesMessages = listener.awaitMessages();

        assertNotNull(server);
        assertThat(bytesMessages.size(), is(5));
        assertNotNull(bytesMessages.get(0));

        // Ensure messages are received in the same order they were sent
        for (int i = 0; i < 5; i++) {
            assertThat(JMSHelper.objectFromMsg(bytesMessages.get(i)), is(i + ""));
        }
    }
}
 
开发者ID:florentw,项目名称:bench,代码行数:26,代码来源:JMSClientServerTest.java

示例7: validateBytesConvertedToBytesMessageOnSendOverJNDI

import javax.jms.BytesMessage; //导入依赖的package包/类
@Test
public void validateBytesConvertedToBytesMessageOnSendOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    publisher.publish(destinationName, "hellomq".getBytes());

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    byte[] bytes = new byte[7];
    ((BytesMessage) receivedMessage).readBytes(bytes);
    assertEquals("hellomq", new String(bytes));

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:17,代码来源:JMSPublisherConsumerTest.java

示例8: validateJmsHeadersAndPropertiesAreTransferredFromFFAttributesOverJNDI

import javax.jms.BytesMessage; //导入依赖的package包/类
@Test
public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributesOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    Map<String, String> flowFileAttributes = new HashMap<>();
    flowFileAttributes.put("foo", "foo");
    flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic");
    publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes);

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    assertEquals("foo", receivedMessage.getStringProperty("foo"));
    assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic);
    assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:20,代码来源:JMSPublisherConsumerTest.java

示例9: validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes

import javax.jms.BytesMessage; //导入依赖的package包/类
@Test
public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    Map<String, String> flowFileAttributes = new HashMap<>();
    flowFileAttributes.put("foo", "foo");
    flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic");
    publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes);

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    assertEquals("foo", receivedMessage.getStringProperty("foo"));
    assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic);
    assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:20,代码来源:JMSPublisherConsumerTest.java

示例10: doSendBinaryMessage

import javax.jms.BytesMessage; //导入依赖的package包/类
private void doSendBinaryMessage( final Session session, final Destination destination,
                                  final byte[] bytes,
                                  final Map<String, ?> properties ) throws JMSException {

    try {
        BytesMessage message = session.createBytesMessage();
        message.writeBytes(bytes);
        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,代码行数:22,代码来源:JmsClient.java

示例11: send

import javax.jms.BytesMessage; //导入依赖的package包/类
public void send(byte[] message) {
    if (session == null) {
        logger.warning("Session is null - sending monitoring message aborted");
        return;
    }
    if (queue == null) {
        logger.warning("Queue is null - sending monitoring message aborted");
        return;
    }
    if (producer == null) {
        logger.warning("Producer is null - sending monitoring message aborted");
        return;
    }
    try {
        BytesMessage bytesMessage = session.createBytesMessage();
        bytesMessage.writeBytes(message);
        producer.send(bytesMessage);
    } catch (JMSException ex) {
        logger.log(Level.SEVERE, "Message sending error", ex);
    }
    //logger.info("Sent monitoring message");
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:23,代码来源:MonitoringMessageSender.java

示例12: sendMessage

import javax.jms.BytesMessage; //导入依赖的package包/类
@Override
public void sendMessage(final Message message) {
	this.jmsTemplate.send(createDestination(message.getDestination()), new MessageCreator() {
		@Override
		public javax.jms.Message createMessage(Session session) throws JMSException {
			BytesMessage bytesMessage = session.createBytesMessage();
			bytesMessage.writeBytes(message.getBody());
			if(!CollectionUtils.isEmpty(message.getProperties())){
				if(message.getProperties().get("JMSXGroupID") != null){
					bytesMessage.setStringProperty("JMSXGroupID", message.getProperties().get("JMSXGroupID").toString());
				}
				if(message.getProperties().get("JMSXGroupSeq") != null){
					String JMSXGroupSeq = message.getProperties().get("JMSXGroupSeq").toString();
					if(StringUtil.isNumeric(JMSXGroupSeq)){
						bytesMessage.setIntProperty("JMSXGroupSeq", Integer.valueOf(JMSXGroupSeq));
					}
				}
			}
			return bytesMessage;
		}
	});
}
 
开发者ID:yanghuijava,项目名称:elephant,代码行数:23,代码来源:ActivemqProducerService.java

示例13: createBytesMessage

import javax.jms.BytesMessage; //导入依赖的package包/类
void createBytesMessage() throws Exception {
  BytesMessage message = mock(BytesMessage.class);
  when(message.getBodyLength()).thenReturn((long)BYTES.length);
  when(message.readBytes(any(byte[].class))).then(new Answer<Integer>() {
    @Override
    public Integer answer(InvocationOnMock invocation) throws Throwable {
      byte[] buffer = (byte[])invocation.getArguments()[0];
      if (buffer != null) {
        assertEquals(buffer.length, BYTES.length);
        System.arraycopy(BYTES, 0, buffer, 0, BYTES.length);
      }
      return BYTES.length;
    }
  });
  this.message = message;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:17,代码来源:TestDefaultJMSMessageConverter.java

示例14: toMessage

import javax.jms.BytesMessage; //导入依赖的package包/类
/**
 * 
 * @param session
 * @param frame
 * @return
 * @throws JMSException
 */
public Message toMessage(Session session, Frame frame) throws JMSException {
	// FIXME buffer pool
	final Message msg;
	if (frame.contains(CONTENT_LENGTH)) {
		final ByteBuffer buf = frame.body().get();
		byte[] bytes = new byte[buf.remaining()];
		buf.get(bytes);
		final BytesMessage bm = session.createBytesMessage();
		bm.writeBytes(bytes);
		msg = bm;
	} else {
		msg = session.createTextMessage(UTF_8.decode(frame.body().get()).toString());
	}
	copyHeaders(session, frame, msg);
	return msg;
}
 
开发者ID:dansiviter,项目名称:cito,代码行数:24,代码来源:Factory.java

示例15: toMessage_bytes

import javax.jms.BytesMessage; //导入依赖的package包/类
@Test
public void toMessage_bytes() throws JMSException {
	final javax.jms.Session session = mock(javax.jms.Session.class);
	final Frame frame = mock(Frame.class);
	final ByteBuffer buffer = ByteBuffer.wrap(new byte[0]).asReadOnlyBuffer();
	when(frame.body()).thenReturn(Optional.of(buffer));
	when(frame.headers()).thenReturn(new MultivaluedHashMap<>());
	when(frame.contains(Standard.CONTENT_LENGTH)).thenReturn(true);
	final BytesMessage message = mock(BytesMessage.class);
	when(session.createBytesMessage()).thenReturn(message);

	this.factory.toMessage(session, frame);

	verify(frame).body();
	verify(frame, times(2)).headers();
	verify(frame).contains(Standard.CONTENT_LENGTH);
	verify(session).createBytesMessage();
	verify(message).setJMSCorrelationID(null);
	verify(message).writeBytes(new byte[0]);
	verifyNoMoreInteractions(session, frame, message);
}
 
开发者ID:dansiviter,项目名称:cito,代码行数:22,代码来源:FactoryTest.java


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