Refine search
/** * Create a JMS BytesMessage for the given byte array. * @param bytes the byte array to convert * @param session current JMS session * @return the resulting message * @throws JMSException if thrown by JMS methods * @see javax.jms.Session#createBytesMessage */ protected BytesMessage createMessageForByteArray(byte[] bytes, Session session) throws JMSException { BytesMessage message = session.createBytesMessage(); message.writeBytes(bytes); return message; }
final Session jmsSession = wrappedProducer.getSession(); final MessageProducer producer = wrappedProducer.getProducer(); final BytesMessage message = jmsSession.createBytesMessage(); message.writeBytes("Hello Bytes".getBytes()); producer.send(message); jmsSession.commit();
/** * Sends a custom Avro Record to the service. * @param <T> type of Avro Record to send * @param t the Record to send * @param contentType optional content type for the JMS header * @throws IOException on errors packing the Record into a JMS BytesMessage * @throws JMSException on errors sending the Record */ protected <T extends IndexedRecord> void send( T t, String contentType) throws IOException, JMSException{ BytesMessage message = mySession.createBytesMessage(); ((JMSBytesMessage)message).setContentType(contentType); QpidUtils.packAvroMessage(t, message); myCommandSender.send(message); }
@Override public void publish(byte[] event) { BytesMessage message; try { message = session.createBytesMessage(); message.writeBytes(event); producer.send(message); } catch (JMSException e) { e.printStackTrace(); } }
private void writeWindowId(String appId, int operatorId, long windowId) throws JMSException { BytesMessage message = getBase().getSession().createBytesMessage(); message.setStringProperty(APP_OPERATOR_ID, appId + "_" + operatorId); message.writeLong(windowId); producer.send(message); logger.debug("Message with windowId {} sent", windowId); }
/** * Marshal the given object to a {@link BytesMessage}. * @param object the object to be marshalled * @param session current JMS session * @param marshaller the marshaller to use * @return the resulting message * @throws JMSException if thrown by JMS methods * @throws IOException in case of I/O errors * @throws XmlMappingException in case of OXM mapping errors * @see Session#createBytesMessage * @see Marshaller#marshal(Object, Result) */ protected BytesMessage marshalToBytesMessage(Object object, Session session, Marshaller marshaller) throws JMSException, IOException, XmlMappingException { ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); StreamResult streamResult = new StreamResult(bos); marshaller.marshal(object, streamResult); BytesMessage message = session.createBytesMessage(); message.writeBytes(bos.toByteArray()); return message; }
@Override public void publish(byte[] event) { BytesMessage message; try { message = session.createBytesMessage(); message.writeBytes(event); producer.send(message); } catch (JMSException e) { e.printStackTrace(); } }
private void sendRequest(String methodName, Object []args) throws JMSException, IOException { BytesMessage message = _jmsSession.createBytesMessage(); BytesMessageOutputStream os = new BytesMessageOutputStream(message); AbstractHessianOutput out = _factory.getHessianOutput(os); out.call(methodName, args); out.flush(); _producer.send(message); } }
/** * Map the given object to a {@link BytesMessage}. * @param object the object to be mapped * @param session current JMS session * @param objectWriter the writer to use * @return the resulting message * @throws JMSException if thrown by JMS methods * @throws IOException in case of I/O errors * @since 4.3 * @see Session#createBytesMessage */ protected BytesMessage mapToBytesMessage(Object object, Session session, ObjectWriter objectWriter) throws JMSException, IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); OutputStreamWriter writer = new OutputStreamWriter(bos, this.encoding); objectWriter.writeValue(writer, object); BytesMessage message = session.createBytesMessage(); message.writeBytes(bos.toByteArray()); if (this.encodingPropertyName != null) { message.setStringProperty(this.encodingPropertyName, this.encoding); } return message; }
public void send(byte[] bytes) throws Exception { BytesMessage bm = session.createBytesMessage(); bm.writeBytes(bytes); bm.setStringProperty("channelId", channelId); producer.send(bm); }
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { InputStream is = request.getInputStream(); try { BytesMessage message = _jmsSession.createBytesMessage(); BytesMessageOutputStream out = new BytesMessageOutputStream(message); WriteStream ws = VfsStream.openWrite(out); ws.writeStream(is); ws.flush(); out.flush(); _producer.send(message); } catch (JMSException e) { throw new ServletException(e); } } }
@Override public Message createMessage(Session session) throws JMSException { BytesMessage message = session.createBytesMessage(); message.writeBytes(messageBytes); setMessageHeaderAndProperties(message, flowFileAttributes); return message; } });
@Override public void publish(Object message) { Session pubSession = null; try { if (connection != null) { pubSession = connection.createSession(false, TopicSession.AUTO_ACKNOWLEDGE); MessageProducer publisher = pubSession.createProducer(destination); BytesMessage bytesMessage = pubSession.createBytesMessage(); bytesMessage.writeBytes((byte[]) message); publisher.send(bytesMessage); } } catch (JMSException e) { log.error("Global cache invalidation: Error in publishing the message", e); } finally { if (pubSession != null) { try { pubSession.close(); } catch (JMSException e) { log.error("Global cache invalidation: Error in publishing the message", e); } } } }
private void postGetMessage(Session session, Destination destination, Destination replyTo) throws Exception { MessageProducer producer = session.createProducer(destination); Message message = session.createBytesMessage(); message.setJMSReplyTo(replyTo); message.setStringProperty("Accept", "application/xml"); message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/books/123"); message.setStringProperty(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "GET"); producer.send(message); producer.close(); }
protected Message createMessage(int i) throws Exception { Message answer; if (payload != null) { answer = session.createBytesMessage(); ((BytesMessage) answer).writeBytes(payload); } else { if (textMessageSize > 0) { if (messageText == null) { messageText = readInputStream(getClass().getResourceAsStream("demo.txt"), textMessageSize, i); } } else if (payloadUrl != null) { messageText = readInputStream(new URL(payloadUrl).openStream(), -1, i); } else if (message != null) { messageText = message; } else { messageText = createDefaultMessage(i); } answer = session.createTextMessage(messageText); } if ((msgGroupID != null) && (!msgGroupID.isEmpty())) { answer.setStringProperty("JMSXGroupID", msgGroupID); } return answer; }
/** * Called when new data arrives to the sink, and forwards it to RMQ. * * @param value * The incoming data */ @Override public void invoke(IN value) { try { byte[] bytes = serializationSchema.serialize(value); BytesMessage message = session.createBytesMessage(); message.writeBytes(bytes); producer.send(message); } catch (JMSException e) { if (logFailuresOnly) { LOG.error("Failed to send message to ActiveMQ", e); } else { throw new RuntimeException("Failed to send message to ActiveMQ", e); } } }
@Test public void testBodyConversion() throws Throwable { try ( Connection conn = cf.createConnection(); ) { Session sess = conn.createSession(); MessageProducer producer = sess.createProducer(queue); MessageConsumer cons = sess.createConsumer(queue); conn.start(); BytesMessage bytesMessage = sess.createBytesMessage(); producer.send(bytesMessage); Message msg = cons.receiveNoWait(); assertNotNull(msg); try { msg.getBody(String.class); fail("Exception expected"); } catch (MessageFormatException e) { } } } }
@Test public void toBytesMessage() throws Exception { BytesMessage bytesMessageMock = mock(BytesMessage.class); Date toBeMarshalled = new Date(); given(sessionMock.createBytesMessage()).willReturn(bytesMessageMock); converter.toMessage(toBeMarshalled, sessionMock); verify(bytesMessageMock).setStringProperty("__encoding__", "UTF-8"); verify(bytesMessageMock).setStringProperty("__typeid__", Date.class.getName()); verify(bytesMessageMock).writeBytes(isA(byte[].class)); }
/** * Called when new data arrives to the sink, and forwards it to RMQ. * * @param value * The incoming data */ @Override public void invoke(IN value, Context context) throws Exception { try { byte[] bytes = serializationSchema.serialize(value); BytesMessage message = session.createBytesMessage(); message.writeBytes(bytes); producer.send(message); } catch (JMSException e) { if (logFailuresOnly) { LOG.error("Failed to send message to ActiveMQ", e); } else { throw new RuntimeException("Failed to send message to ActiveMQ", e); } } }
@Test public void testSimpleLargeMessage2() throws Exception { conn = cf.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer prod = session.createProducer(queue1); BytesMessage m = session.createBytesMessage(); m.setObjectProperty("JMS_AMQ_InputStream", ActiveMQTestBase.createFakeLargeStream(10)); prod.send(m); conn.close(); conn = cf.createConnection(); session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = session.createConsumer(queue1); conn.start(); BytesMessage rm = (BytesMessage) cons.receive(10000); byte[] data = new byte[1024]; System.out.println("Message = " + rm); int numberOfBytes = rm.readBytes(data); Assert.assertEquals(10, numberOfBytes); for (int j = 0; j < numberOfBytes; j++) { Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), data[j]); } Assert.assertNotNull(rm); }