org.apache.activemq.command.ActiveMQMessage Java Examples
The following examples show how to use
org.apache.activemq.command.ActiveMQMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleNetworkTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 60 * 1000) public void testMessageCompression() throws Exception { ActiveMQConnection localAmqConnection = (ActiveMQConnection) localConnection; localAmqConnection.setUseCompression(true); MessageConsumer consumer1 = remoteSession.createConsumer(included); MessageProducer producer = localSession.createProducer(included); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); waitForConsumerRegistration(localBroker, 1, included); for (int i = 0; i < MESSAGE_COUNT; i++) { Message test = localSession.createTextMessage("test-" + i); producer.send(test); Message msg = consumer1.receive(3000); assertNotNull(msg); ActiveMQMessage amqMessage = (ActiveMQMessage) msg; assertTrue(amqMessage.isCompressed()); } // ensure no more messages received assertNull(consumer1.receive(1000)); }
Example #2
Source File: JMSUsecase1Test.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSendReceive() throws Exception { // Send a message to the broker. connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQDestination destination = createDestination(session, destinationType); MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(this.deliveryMode); MessageConsumer consumer = session.createConsumer(destination); ActiveMQMessage message = new ActiveMQMessage(); producer.send(message); // Make sure only 1 message was delivered. assertNotNull(consumer.receive(1000)); assertNull(consumer.receiveNoWait()); }
Example #3
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 6 votes |
public static MessageDispatch createMessageDispatch(MessageReference reference, ICoreMessage message, WireFormat marshaller, AMQConsumer consumer) throws IOException { ActiveMQMessage amqMessage = toAMQMessage(reference, message, marshaller, consumer); //we can use core message id for sequenceId amqMessage.getMessageId().setBrokerSequenceId(message.getMessageID()); MessageDispatch md = new MessageDispatch(); md.setConsumerId(consumer.getId()); md.setRedeliveryCounter(reference.getDeliveryCount() - 1); md.setDeliverySequenceId(amqMessage.getMessageId().getBrokerSequenceId()); md.setMessage(amqMessage); ActiveMQDestination destination = amqMessage.getDestination(); md.setDestination(destination); return md; }
Example #4
Source File: PluginBrokerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override protected void assertMessageValid(int index, Message message) throws JMSException { // check if broker path has been set assertEquals("localhost", message.getStringProperty("BrokerPath")); ActiveMQMessage amqMsg = (ActiveMQMessage) message; if (index == 7) { // check custom expiration assertTrue("expiration is in range, depends on two distinct calls to System.currentTimeMillis", 1500 < amqMsg.getExpiration() - amqMsg.getTimestamp()); } else if (index == 9) { // check ceiling assertTrue("expiration ceeling is in range, depends on two distinct calls to System.currentTimeMillis", 59500 < amqMsg.getExpiration() - amqMsg.getTimestamp()); } else { // check default expiration assertEquals(1000, amqMsg.getExpiration() - amqMsg.getTimestamp()); } super.assertMessageValid(index, message); }
Example #5
Source File: ActiveMQMessageConsumerDispatchInterceptor.java From pinpoint with Apache License 2.0 | 6 votes |
private boolean validate(Object target, Object[] args) { if (!(target instanceof ActiveMQMessageConsumer)) { return false; } if (!(target instanceof ActiveMQSessionGetter)) { if (isDebug) { logger.debug("Invalid target object. Need field accessor({}).", ActiveMQSessionGetter.class.getName()); } return false; } if (!validateTransport(((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession())) { return false; } if (args == null || args.length < 1) { return false; } if (!(args[0] instanceof MessageDispatch)) { return false; } MessageDispatch md = (MessageDispatch) args[0]; Message message = md.getMessage(); if (!(message instanceof ActiveMQMessage)) { return false; } return true; }
Example #6
Source File: AdvisoryTempDestinationTests.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void testTempMessageConsumedAdvisory() throws Exception { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TemporaryQueue queue = s.createTemporaryQueue(); MessageConsumer consumer = s.createConsumer(queue); Topic advisoryTopic = AdvisorySupport.getMessageConsumedAdvisoryTopic((ActiveMQDestination) queue); MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic); //start throwing messages at the consumer MessageProducer producer = s.createProducer(queue); BytesMessage m = s.createBytesMessage(); m.writeBytes(new byte[1024]); producer.send(m); String id = m.getJMSMessageID(); Message msg = consumer.receive(1000); assertNotNull(msg); msg = advisoryConsumer.receive(1000); assertNotNull(msg); ActiveMQMessage message = (ActiveMQMessage) msg; ActiveMQMessage payload = (ActiveMQMessage) message.getDataStructure(); String originalId = payload.getJMSMessageID(); assertEquals(originalId, id); }
Example #7
Source File: ActiveMQMessageConsumerDispatchInterceptor.java From pinpoint with Apache License 2.0 | 6 votes |
private Trace createTrace(Object target, Object[] args) { if (!validate(target, args)) { return null; } MessageDispatch md = (MessageDispatch) args[0]; ActiveMQMessage message = (ActiveMQMessage) md.getMessage(); if (filterDestination(message.getDestination())) { return null; } // These might trigger unmarshalling. if (!ActiveMQClientHeader.getSampled(message, true)) { return traceContext.disableSampling(); } final TraceId traceId = populateTraceIdFromRequest(message); final Trace trace = traceId == null ? traceContext.newTraceObject() : traceContext.continueTraceObject(traceId); if (trace.canSampled()) { SpanRecorder recorder = trace.getSpanRecorder(); recordRootSpan(recorder, target, args); } return trace; }
Example #8
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 6 votes |
private static void setAMQMsgObjectProperties(final ActiveMQMessage amqMsg, final ICoreMessage coreMessage, final Set<SimpleString> props, final AMQConsumer consumer) throws IOException { for (SimpleString s : props) { final String keyStr = s.toString(); if (!coreMessage.containsProperty(ManagementHelper.HDR_NOTIFICATION_TYPE) && (keyStr.startsWith("_AMQ") || keyStr.startsWith("__HDR_"))) { continue; } final Object prop = coreMessage.getObjectProperty(s); try { if (prop instanceof SimpleString) { amqMsg.setObjectProperty(keyStr, prop.toString()); } else { if (keyStr.equals(MessageUtil.JMSXDELIVERYCOUNT) && prop instanceof Long) { Long l = (Long) prop; amqMsg.setObjectProperty(keyStr, l.intValue()); } else { amqMsg.setObjectProperty(keyStr, prop); } } } catch (JMSException e) { throw new IOException("exception setting property " + s + " : " + prop, e); } } }
Example #9
Source File: AdvisoryTests.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void testMessageConsumedAdvisory() throws Exception { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); MessageConsumer consumer = s.createConsumer(queue); Topic advisoryTopic = AdvisorySupport.getMessageConsumedAdvisoryTopic((ActiveMQDestination) queue); MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic); //start throwing messages at the consumer MessageProducer producer = s.createProducer(queue); BytesMessage m = s.createBytesMessage(); m.writeBytes(new byte[1024]); producer.send(m); String id = m.getJMSMessageID(); Message msg = consumer.receive(1000); assertNotNull(msg); msg = advisoryConsumer.receive(1000); assertNotNull(msg); ActiveMQMessage message = (ActiveMQMessage) msg; ActiveMQMessage payload = (ActiveMQMessage) message.getDataStructure(); String originalId = payload.getJMSMessageID(); assertEquals(originalId, id); }
Example #10
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 5 votes |
private static void setAMQMsgDataStructure(final ActiveMQMessage amqMsg, final WireFormat marshaller, final byte[] dsBytes) throws IOException { ByteSequence seq = new ByteSequence(dsBytes); DataStructure ds = (DataStructure) marshaller.unmarshal(seq); amqMsg.setDataStructure(ds); }
Example #11
Source File: UnknownHandlingSelectorTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { message = new ActiveMQMessage(); message.setJMSDestination(new ActiveMQTopic("FOO.BAR")); message.setJMSType("selector-test"); message.setJMSMessageID("connection:1:1:1:1"); message.setBooleanProperty("trueProp", true); message.setBooleanProperty("falseProp", false); message.setObjectProperty("nullProp", null); }
Example #12
Source File: JMSUsecaseTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void testSendReceive() throws Exception { // Send a message to the broker. connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = createDestination(session, destinationType); MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(this.deliveryMode); MessageConsumer consumer = session.createConsumer(destination); ActiveMQMessage message = new ActiveMQMessage(); producer.send(message); // Make sure only 1 message was delivered. assertNotNull(consumer.receive(1000)); assertNull(consumer.receiveNoWait()); }
Example #13
Source File: LargeMessageTestSupport.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected boolean isSame(BytesMessage msg1) throws Exception { boolean result = false; ((ActiveMQMessage) msg1).setReadOnlyBody(true); for (int i = 0; i < LARGE_MESSAGE_SIZE; i++) { result = msg1.readByte() == largeMessageData[i]; if (!result) { break; } } return result; }
Example #14
Source File: DurableSubscriptionUnsubscribeTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void createAdvisorySubscription() throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer advisoryConsumer = session.createConsumer(AdvisorySupport.getConsumerAdvisoryTopic(topic)); advisoryConsumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { if (((ActiveMQMessage) message).getDataStructure() instanceof RemoveSubscriptionInfo) { advisories.incrementAndGet(); } } }); }
Example #15
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 5 votes |
private static void setAMQMsgClusterPath(final ActiveMQMessage amqMsg, final String clusterPath) { String[] cluster = clusterPath.split(","); BrokerId[] bids = new BrokerId[cluster.length]; for (int i = 0; i < bids.length; i++) { bids[i] = new BrokerId(cluster[i]); } amqMsg.setCluster(bids); }
Example #16
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 5 votes |
private static void setAMQMsgBrokerPath(final ActiveMQMessage amqMsg, final String brokerPath) { String[] brokers = brokerPath.split(","); BrokerId[] bids = new BrokerId[brokers.length]; for (int i = 0; i < bids.length; i++) { bids[i] = new BrokerId(brokers[i]); } amqMsg.setBrokerPath(bids); }
Example #17
Source File: OpenWireConnection.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void onSlowConsumer(ServerConsumer consumer) { if (consumer.getProtocolData() != null && consumer.getProtocolData() instanceof AMQConsumer) { AMQConsumer amqConsumer = (AMQConsumer) consumer.getProtocolData(); ActiveMQTopic topic = AdvisorySupport.getSlowConsumerAdvisoryTopic(amqConsumer.getOpenwireDestination()); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); try { advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_CONSUMER_ID, amqConsumer.getId().toString()); protocolManager.fireAdvisory(context, topic, advisoryMessage, amqConsumer.getId(), null); } catch (Exception e) { ActiveMQServerLogger.LOGGER.warn("Error during method invocation", e); } } }
Example #18
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 5 votes |
private static void setAMQMsgDlqDeliveryFailureCause(final ActiveMQMessage amqMsg, final SimpleString dlqCause) throws IOException { try { amqMsg.setStringProperty(ActiveMQMessage.DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY, dlqCause.toString()); } catch (JMSException e) { throw new IOException("failure to set dlq property " + dlqCause, e); } }
Example #19
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 5 votes |
private static void setAMQMsgHdrLastValueName(final ActiveMQMessage amqMsg, final SimpleString lastValueProperty) throws IOException { try { amqMsg.setStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_LAST_VALUE_NAME.toString(), lastValueProperty.toString()); } catch (JMSException e) { throw new IOException("failure to set lvq property " + lastValueProperty, e); } }
Example #20
Source File: A.java From a with Apache License 2.0 | 5 votes |
protected void displayAdvisoryMessage(ActiveMQMessage cmdMsg) throws IOException, JMSException { final String topic = cmdMsg.getJMSDestination().toString(); final String advisoryMsg = advisoryDataStructureToString(cmdMsg.getDataStructure()); final String advisoryType = cmdMsg.getDataStructure() != null ? "Type: " + dataStructureTypeToString(cmdMsg.getDataStructure().getDataStructureType()) : ""; output("Advisory on " + topic + advisoryType + (advisoryMsg != null ? " Info " + advisoryMsg : "")); }
Example #21
Source File: ActiveMQMessageConsumerDispatchInterceptor.java From pinpoint with Apache License 2.0 | 5 votes |
private TraceId populateTraceIdFromRequest(ActiveMQMessage message) { String transactionId = ActiveMQClientHeader.getTraceId(message, null); if (transactionId == null) { return null; } long parentSpanId = ActiveMQClientHeader.getParentSpanId(message, SpanId.NULL); long spanId = ActiveMQClientHeader.getSpanId(message, SpanId.NULL); short flags = ActiveMQClientHeader.getFlags(message, (short) 0); return traceContext.createTraceId(transactionId, parentSpanId, spanId, flags); }
Example #22
Source File: ActiveMQMessageConsumerDispatchInterceptor.java From pinpoint with Apache License 2.0 | 5 votes |
private void recordRootSpan(SpanRecorder recorder, Object target, Object[] args) { recorder.recordServiceType(ActiveMQClientConstants.ACTIVEMQ_CLIENT); recorder.recordApi(CONSUMER_ENTRY_METHOD_DESCRIPTOR); ActiveMQSession session = ((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession(); ActiveMQConnection connection = session.getConnection(); Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport()); final String endPoint = getEndPoint(transport); // Endpoint should be the local socket address of the consumer. recorder.recordEndPoint(endPoint); final String remoteAddress = transport.getRemoteAddress(); // Remote address is the socket address of where the consumer is connected to. recorder.recordRemoteAddress(remoteAddress); MessageDispatch md = (MessageDispatch) args[0]; ActiveMQMessage message = (ActiveMQMessage) md.getMessage(); ActiveMQDestination destination = message.getDestination(); // Rpc name is the URI of the queue/topic we're consuming from. recorder.recordRpcName(destination.getQualifiedName()); // Record acceptor host as the queue/topic name in order to generate virtual queue node. recorder.recordAcceptorHost(destination.getPhysicalName()); String parentApplicationName = ActiveMQClientHeader.getParentApplicationName(message, null); if (!recorder.isRoot() && parentApplicationName != null) { short parentApplicationType = ActiveMQClientHeader.getParentApplicationType(message, ServiceType.UNDEFINED.getCode()); recorder.recordParentApplication(parentApplicationName, parentApplicationType); } }
Example #23
Source File: ActiveMQClientHeader.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public final void setMessage(Message message, ActiveMQClientHeader key, T value) throws JMSException { String id = key.id; if (message instanceof ActiveMQMessage) { ActiveMQMessage activeMQMessage = (ActiveMQMessage) message; if (activeMQMessage.isReadOnlyProperties()) { activeMQMessage.setReadOnlyProperties(false); setMessage0(message, id, value); activeMQMessage.setReadOnlyProperties(true); return; } } setMessage0(message, id, value); }
Example #24
Source File: JmsIOTest.java From beam with Apache License 2.0 | 5 votes |
/** Test the checkpoint mark default coder, which is actually AvroCoder. */ @Test public void testCheckpointMarkDefaultCoder() throws Exception { JmsCheckpointMark jmsCheckpointMark = new JmsCheckpointMark(); jmsCheckpointMark.add(new ActiveMQMessage()); Coder coder = new JmsIO.UnboundedJmsSource(null).getCheckpointMarkCoder(); CoderProperties.coderSerializable(coder); CoderProperties.coderDecodeEncodeEqual(coder, jmsCheckpointMark); }
Example #25
Source File: JmsIOTest.java From beam with Apache License 2.0 | 5 votes |
private ConnectionFactory withSlowAcks(ConnectionFactory factory, long delay) { return proxyMethod( factory, ConnectionFactory.class, "createConnection", (Connection connection) -> proxyMethod( connection, Connection.class, "createSession", (Session session) -> proxyMethod( session, Session.class, "createConsumer", (MessageConsumer consumer) -> proxyMethod( consumer, MessageConsumer.class, "receiveNoWait", (ActiveMQMessage message) -> { final Callback originalCallback = message.getAcknowledgeCallback(); message.setAcknowledgeCallback( () -> { Thread.sleep(delay); originalCallback.execute(); }); return message; })))); }
Example #26
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 4 votes |
private static void setAMQMsgReplyTo(final ActiveMQMessage amqMsg, final WireFormat marshaller, final byte[] replyToBytes) throws IOException { ActiveMQDestination replyTo = (ActiveMQDestination) marshaller.unmarshal(new ByteSequence(replyToBytes)); amqMsg.setReplyTo(replyTo); }
Example #27
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 4 votes |
private static void setAMQMsgOriginalTransactionId(final ActiveMQMessage amqMsg, final WireFormat marshaller, final byte[] origTxIdBytes) throws IOException { TransactionId origTxId = (TransactionId) marshaller.unmarshal(new ByteSequence(origTxIdBytes)); amqMsg.setOriginalTransactionId(origTxId); }
Example #28
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 4 votes |
private static void setAMQMsgOriginalDestination(final ActiveMQMessage amqMsg, final WireFormat marshaller, final byte[] origDestBytes) throws IOException { ActiveMQDestination origDest = (ActiveMQDestination) marshaller.unmarshal(new ByteSequence(origDestBytes)); amqMsg.setOriginalDestination(origDest); }
Example #29
Source File: A.java From a with Apache License 2.0 | 4 votes |
protected String advisoryDataStructureToString(final DataStructure dataStructure) throws JMSException { if( dataStructure != null) { switch( dataStructure.getDataStructureType()) { case CommandTypes.PRODUCER_INFO: ProducerInfo pi = (ProducerInfo)dataStructure; return "ProducerId: " + pi.getProducerId().toString() + " destination: " + pi.getDestination().toString(); case CommandTypes.CONSUMER_INFO: ConsumerInfo ci = (ConsumerInfo)dataStructure; return "ConsumerId: " + ci.getConsumerId().toString() + " destination: " + ci.getDestination().toString(); case CommandTypes.CONNECTION_INFO: ConnectionInfo connInfo = (ConnectionInfo) dataStructure; String connStr = connInfo.getUserName() != null ? connInfo.getUserName() + "@" + connInfo.getClientIp() : connInfo.getClientIp(); return "ConnectionId: " + connInfo.getConnectionId().toString() + " Connection from: " + connStr + " clientId: " + connInfo.getClientId(); case CommandTypes.REMOVE_INFO: RemoveInfo removeInfo = (RemoveInfo)dataStructure; return advisoryDataStructureToString(removeInfo.getObjectId()); case CommandTypes.ACTIVEMQ_MESSAGE: ActiveMQMessage messageInfo = (ActiveMQMessage)dataStructure; return "messageId: " + messageInfo.getStringProperty("originalMessageId"); case CommandTypes.DESTINATION_INFO: DestinationInfo destInfo = (DestinationInfo)dataStructure; return destInfo.getDestination().getQualifiedName() + (destInfo.getOperationType() == DestinationInfo.ADD_OPERATION_TYPE ? " added" : " removed"); case CommandTypes.BROKER_INFO: BrokerInfo brokerInfo = (BrokerInfo)dataStructure; return "brokerId: " + brokerInfo.getBrokerId() + " brokerName: " + brokerInfo.getBrokerName() + " brokerURL: " + brokerInfo.getBrokerURL(); default: return null; } } else { return null; } }
Example #30
Source File: ConsumeJMSManualTest.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testUnsupportedMessage() throws Exception { MessageCreator messageCreator = session -> new ActiveMQMessage(); send(messageCreator); }