本文整理汇总了Java中org.apache.activemq.command.ActiveMQObjectMessage类的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQObjectMessage类的具体用法?Java ActiveMQObjectMessage怎么用?Java ActiveMQObjectMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActiveMQObjectMessage类属于org.apache.activemq.command包,在下文中一共展示了ActiveMQObjectMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeName
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
@Override
protected String getTypeName() {
return ActiveMQObjectMessage.class.getName();
}
示例2: fromHeaders
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
/**
* {@inheritDoc}. Additionally sets <code>AMQ_SCHEDULED_DELAY</code> using
* <code>MotechEventConfig</code> variables.
*/
@Override
public void fromHeaders(MessageHeaders messageHeaders, Message message) {
super.fromHeaders(messageHeaders, message);
try {
MotechEvent motechEvent = (MotechEvent) ((ActiveMQObjectMessage) message).getObject();
if (motechEvent.isInvalid()) {
long redeliveryCount = motechEvent.getMessageRedeliveryCount();
Double delay = motechEventConfig.getMessageRedeliveryDelay() * MILLIS_PER_SEC *
((Math.pow(2, redeliveryCount - 1)));
LOGGER.debug("Redelivering " + motechEvent + " after " + delay + " millis.");
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay.longValue());
}
} catch (JMSException e) {
LOGGER.error("Failed to set header", e);
}
}
示例3: testObjectMessageCompression
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
@Test
public void testObjectMessageCompression() throws Exception {
MessageConsumer consumer1 = remoteSession.createConsumer(included);
MessageProducer producer = localSession.createProducer(included);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
waitForConsumerRegistration(localBroker, 1, included);
StringBuilder payload = new StringBuilder("test-");
for (int i = 0; i < 100; ++i) {
payload.append(UUID.randomUUID().toString());
}
Message test = localSession.createObjectMessage(payload.toString());
producer.send(test);
Message msg = consumer1.receive(RECEIVE_TIMEOUT_MILLS);
assertNotNull(msg);
ActiveMQObjectMessage message = (ActiveMQObjectMessage) msg;
assertTrue(message.isCompressed());
assertEquals(payload.toString(), message.getObject());
}
示例4: getMessagesFromBroker
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
protected List<Object[]> getMessagesFromBroker() throws JMSException {
List<Object[]> messages = new ArrayList<Object[]>();
Message message = new ActiveMQMessage();
while (message != null) {
message = messageConsumer.receive(1000);
if (message == null) {
break;
}
Serializable obj = ((ActiveMQObjectMessage)message).getObject();
if (obj != null && obj instanceof Object[]) {
messages.add((Object[])obj);
}
}
return messages;
}
示例5: onMessage
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
@Override
public void onMessage(Message message) {
//TODO add transactional logic here with txn manager
if (message instanceof ObjectMessage) {
ServiceRequest serviceRequest = null;
try {
ActiveMQObjectMessage msg = (ActiveMQObjectMessage) message;
serviceRequest = (ServiceRequest) msg.getObject();
ServiceRequestType serviceRequestType = serviceRequest.getRequestType();
//Process the json
serviceRequestType.process(serviceRequest);
} catch (Exception e) {
LOG.error("Error processing json: " + (serviceRequest==null?"":serviceRequest.getJson()), e);
//TODO respond back to client using the request id or set the status of the request id to failure
//TODO Handle poison messages
}
}
}
示例6: toMessage
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
public Message toMessage(Object obj, Session session) throws JMSException,
MessageConversionException {
if (obj instanceof InvokeMessage) {
ActiveMQObjectMessage objMsg = (ActiveMQObjectMessage) session
.createObjectMessage();
long delay=5*1000;
System.out.println("延时:"+delay/1000+"秒");
System.out.println("msgId:"+objMsg.getJMSMessageID());
objMsg.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
// objMsg.setExpiration(2000);
Map<String, byte[]> map = new HashMap<String, byte[]>();
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
map.put("InvokeMessage", bos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
objMsg.setObjectProperty("Map", map);
return objMsg;
} else {
throw new JMSException("Object:[" + obj + "] is not InvokeMessage");
}
}
示例7: transformToMap
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
/**
* Transform an ActiveMQMessage to a Map
*
* @param msg - object message to transform
* @return map object
* @throws JMSException
*/
protected Map transformToMap(ActiveMQObjectMessage msg) throws JMSException {
Properties props = new Properties();
props.putAll(transformToMap((ActiveMQMessage)msg));
if (msg.getObject() != null) {
// Just add the class name and toString value of the object
props.setProperty(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX + "JMSObjectClass", msg.getObject().getClass().getName());
props.setProperty(AmqMessagesUtil.JMS_MESSAGE_BODY_PREFIX + "JMSObjectString", getDisplayString(msg.getObject()));
}
return props;
}
示例8: onMessage
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
public void onMessage(Message message) {
try {
// receive log event in your consumer
LoggingEvent event = (LoggingEvent)((ActiveMQObjectMessage)message).getObject();
System.out.println("Received log [" + event.getLevel() + "]: "+ event.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: setObjectPayload
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
@Override
public void setObjectPayload(ObjectMessage msg, byte[] rawPayload) throws JMSException {
((ActiveMQObjectMessage) msg).setContent(new ByteSequence(rawPayload));
}
示例10: getObjectPayload
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
@Override
public byte[] getObjectPayload(ObjectMessage msg) throws JMSException {
return ((ActiveMQObjectMessage) msg).getContent().getData();
}
示例11: createObjectMessage
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
protected ActiveMQObjectMessage createObjectMessage(HierarchicalStreamReader in) throws JMSException {
ActiveMQObjectMessage objMsg = new ActiveMQObjectMessage();
Object obj = getXStream().unmarshal(in);
objMsg.setObject((Serializable) obj);
return objMsg;
}
示例12: createObjectMessage
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
@Override
public ObjectMessage createObjectMessage() {
return new ActiveMQObjectMessage();
}
示例13: createObject
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
/**
* @return a new object instance
*/
public DataStructure createObject() {
return new ActiveMQObjectMessage();
}
示例14: createObject
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
@Override
public Object createObject() throws Exception {
ActiveMQObjectMessage info = new ActiveMQObjectMessage();
populateObject(info);
return info;
}
示例15: populateObject
import org.apache.activemq.command.ActiveMQObjectMessage; //导入依赖的package包/类
@Override
protected void populateObject(Object object) throws Exception {
super.populateObject(object);
ActiveMQObjectMessage info = (ActiveMQObjectMessage) object;
}