本文整理汇总了Java中org.apache.activemq.command.ActiveMQMessage类的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQMessage类的具体用法?Java ActiveMQMessage怎么用?Java ActiveMQMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActiveMQMessage类属于org.apache.activemq.command包,在下文中一共展示了ActiveMQMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testActiveMQOriginalDestination
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
@Test
public void testActiveMQOriginalDestination() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("activemq:queue:foo", "Hello World");
assertMockEndpointsSatisfied();
// consume from bar
Exchange out = consumer.receive("activemq:queue:bar", 5000);
assertNotNull(out);
// and we should have foo as the original destination
JmsMessage msg = out.getIn(JmsMessage.class);
Message jms = msg.getJmsMessage();
ActiveMQMessage amq = assertIsInstanceOf(ActiveMQMessage.class, jms);
ActiveMQDestination original = amq.getOriginalDestination();
assertNotNull(original);
assertEquals("foo", original.getPhysicalName());
assertEquals("Queue", original.getDestinationTypeAsString());
}
示例2: send
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
/**
* @param msg
* @throws JMSException
*/
private void send(ActiveMQMessage msg, boolean eosMessage) throws JMSException {
if (properties != null && (messageSequence == 0 || !addPropertiesOnFirstMsgOnly)) {
for (Iterator<String> iter = properties.keySet().iterator(); iter.hasNext();) {
String key = iter.next();
Object value = properties.get(key);
msg.setObjectProperty(key, value);
}
}
msg.setType("org.apache.activemq.Stream");
msg.setGroupID(info.getProducerId().toString());
if (eosMessage) {
msg.setGroupSequence(-1);
} else {
msg.setGroupSequence((int) messageSequence);
}
MessageId id = new MessageId(info.getProducerId(), messageSequence++);
connection.send(info.getDestination(), msg, id, deliveryMode, priority, timeToLive, !eosMessage && !isAlwaysSyncSend());
}
示例3: processInOnly
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
protected boolean processInOnly(final Exchange exchange, final AsyncCallback callback) {
try {
ActiveMQMessage message = getMessage(exchange);
if (message != null) {
message.setDestination(brokerEndpoint.getDestination());
//if the ProducerBrokerExchange is null the broker will create it
ProducerBrokerExchange producerBrokerExchange = (ProducerBrokerExchange) exchange.getProperty(BrokerEndpoint.PRODUCER_BROKER_EXCHANGE);
brokerEndpoint.inject(producerBrokerExchange, message);
}
} catch (Exception e) {
exchange.setException(e);
}
callback.done(true);
return true;
}
示例4: transformToMap
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
/**
* Transform an ActiveMQBytesMessage to a Map
*
* @param msg - bytes message to transform
* @return map object
* @throws JMSException
*/
protected Map transformToMap(ActiveMQBytesMessage msg) throws JMSException {
Properties props = new Properties();
props.putAll(transformToMap((ActiveMQMessage)msg));
long bodyLength = msg.getBodyLength();
byte[] msgBody;
int i = 0;
// Create separate bytes messages
for (i = 0; i < (bodyLength / Integer.MAX_VALUE); i++) {
msgBody = new byte[Integer.MAX_VALUE];
props.setProperty(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX + "JMSBytes:" + (i + 1), new String(msgBody));
}
msgBody = new byte[(int)(bodyLength % Integer.MAX_VALUE)];
props.setProperty(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX + "JMSBytes:" + (i + 1), new String(msgBody));
return props;
}
示例5: onMessage
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
public void onMessage(Message message) {
if (message instanceof ActiveMQMessage) {
ActiveMQMessage activeMessage = (ActiveMQMessage)message;
Object command = activeMessage.getDataStructure();
int count = 0;
if (command instanceof ProducerInfo) {
count = producerCount.incrementAndGet();
count = extractProducerCountFromMessage(message, count);
fireProducerEvent(new ProducerStartedEvent(this, destination, (ProducerInfo)command, count));
} else if (command instanceof RemoveInfo) {
RemoveInfo removeInfo = (RemoveInfo)command;
if (removeInfo.isProducerRemove()) {
count = producerCount.decrementAndGet();
count = extractProducerCountFromMessage(message, count);
fireProducerEvent(new ProducerStoppedEvent(this, destination, (ProducerId)removeInfo.getObjectId(), count));
}
} else {
LOG.warn("Unknown command: " + command);
}
} else {
LOG.warn("Unknown message type: " + message + ". Message ignored");
}
}
示例6: onMessage
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
public void onMessage(Message message) {
if (message instanceof ActiveMQMessage) {
ActiveMQMessage activeMessage = (ActiveMQMessage)message;
Object command = activeMessage.getDataStructure();
int count = 0;
if (command instanceof ConsumerInfo) {
count = consumerCount.incrementAndGet();
count = extractConsumerCountFromMessage(message, count);
fireConsumerEvent(new ConsumerStartedEvent(this, destination, (ConsumerInfo)command, count));
} else if (command instanceof RemoveInfo) {
RemoveInfo removeInfo = (RemoveInfo)command;
if (removeInfo.isConsumerRemove()) {
count = consumerCount.decrementAndGet();
count = extractConsumerCountFromMessage(message, count);
fireConsumerEvent(new ConsumerStoppedEvent(this, destination, (ConsumerId)removeInfo.getObjectId(), count));
}
} else {
LOG.warn("Unknown command: " + command);
}
} else {
LOG.warn("Unknown message type: " + message + ". Message ignored");
}
}
示例7: messageExpired
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
@Override
public void messageExpired(ConnectionContext context, MessageReference messageReference, Subscription subscription) {
super.messageExpired(context, messageReference, subscription);
try {
if(!messageReference.isAdvisory()) {
ActiveMQTopic topic = AdvisorySupport.getExpiredMessageTopic(messageReference.getMessage().getDestination());
Message payload = messageReference.getMessage().copy();
payload.clearBody();
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_MESSAGE_ID, payload.getMessageId().toString());
fireAdvisory(context, topic, payload, null, advisoryMessage);
}
} catch (Exception e) {
handleFireFailure("expired", e);
}
}
示例8: messageDiscarded
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
@Override
public void messageDiscarded(ConnectionContext context, Subscription sub, MessageReference messageReference) {
super.messageDiscarded(context, sub, messageReference);
try {
if (!messageReference.isAdvisory()) {
ActiveMQTopic topic = AdvisorySupport.getMessageDiscardedAdvisoryTopic(messageReference.getMessage().getDestination());
Message payload = messageReference.getMessage().copy();
payload.clearBody();
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
if (sub instanceof TopicSubscription) {
advisoryMessage.setIntProperty(AdvisorySupport.MSG_PROPERTY_DISCARDED_COUNT, ((TopicSubscription)sub).discarded());
}
advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_CONSUMER_ID, sub.getConsumerInfo().getConsumerId().toString());
fireAdvisory(context, topic, payload, null, advisoryMessage);
}
} catch (Exception e) {
handleFireFailure("discarded", e);
}
}
示例9: isFull
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
@Override
public void isFull(ConnectionContext context, Destination destination, Usage usage) {
super.isFull(context, destination, usage);
if (AdvisorySupport.isAdvisoryTopic(destination.getActiveMQDestination()) == false) {
try {
ActiveMQTopic topic = AdvisorySupport.getFullAdvisoryTopic(destination.getActiveMQDestination());
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_USAGE_NAME, usage.getName());
fireAdvisory(context, topic, null, null, advisoryMessage);
} catch (Exception e) {
handleFireFailure("is full", e);
}
}
}
示例10: networkBridgeStarted
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
@Override
public void networkBridgeStarted(BrokerInfo brokerInfo, boolean createdByDuplex, String remoteIp) {
try {
if (brokerInfo != null) {
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
advisoryMessage.setBooleanProperty("started", true);
advisoryMessage.setBooleanProperty("createdByDuplex", createdByDuplex);
advisoryMessage.setStringProperty("remoteIp", remoteIp);
networkBridges.putIfAbsent(brokerInfo, advisoryMessage);
ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic();
ConnectionContext context = new ConnectionContext();
context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
context.setBroker(getBrokerService().getBroker());
fireAdvisory(context, topic, brokerInfo, null, advisoryMessage);
}
} catch (Exception e) {
handleFireFailure("network bridge started", e);
}
}
示例11: networkBridgeStopped
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
@Override
public void networkBridgeStopped(BrokerInfo brokerInfo) {
try {
if (brokerInfo != null) {
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
advisoryMessage.setBooleanProperty("started", false);
networkBridges.remove(brokerInfo);
ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic();
ConnectionContext context = new ConnectionContext();
context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
context.setBroker(getBrokerService().getBroker());
fireAdvisory(context, topic, brokerInfo, null, advisoryMessage);
}
} catch (Exception e) {
handleFireFailure("network bridge stopped", e);
}
}
示例12: createMessageDispatch
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
public MessageDispatch createMessageDispatch(MessageReference reference,
ICoreMessage message,
AMQConsumer consumer) throws IOException, JMSException {
ActiveMQMessage amqMessage = toAMQMessage(reference, message, consumer.getOpenwireDestination());
//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;
}
示例13: onTransportError
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
public void onTransportError() {
if (connect != null) {
if (connected.get() && connect.willTopic() != null && connect.willMessage() != null) {
try {
PUBLISH publish = new PUBLISH();
publish.topicName(connect.willTopic());
publish.qos(connect.willQos());
publish.payload(connect.willMessage());
ActiveMQMessage message = convertMessage(publish);
message.setProducerId(producerId);
message.onSend();
sendToActiveMQ(message, null);
} catch (Exception e) {
LOG.warn("Failed to publish Will Message " + connect.willMessage());
}
}
}
}
示例14: testSendReceive
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
@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);
System.out.println("destionation: " + destination);
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());
}
示例15: testMessageCompression
import org.apache.activemq.command.ActiveMQMessage; //导入依赖的package包/类
@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));
}