本文整理汇总了Java中org.apache.activemq.ScheduledMessage类的典型用法代码示例。如果您正苦于以下问题:Java ScheduledMessage类的具体用法?Java ScheduledMessage怎么用?Java ScheduledMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScheduledMessage类属于org.apache.activemq包,在下文中一共展示了ScheduledMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
public void sendMessage() {
jmsTemplate.send(notifyTopic, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
MapMessage message = session.createMapMessage();
int delay=10*1000;
System.out.println("生产消消息");
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
message.setStringProperty("objectType", "user");
return message;
}
});
}
示例2: fromHeaders
import org.apache.activemq.ScheduledMessage; //导入依赖的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: testCronScheduleWithTtlSet
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
@Test
public void testCronScheduleWithTtlSet() throws Exception {
Connection connection = createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(destination);
connection.start();
MessageProducer producer = session.createProducer(destination);
producer.setTimeToLive(TimeUnit.MINUTES.toMillis(1));
TextMessage message = session.createTextMessage("test msg ");
message.setStringProperty(ScheduledMessage.AMQ_SCHEDULED_CRON, "* * * * *");
producer.send(message);
producer.close();
Thread.sleep(TimeUnit.MINUTES.toMillis(2));
assertNotNull(consumer.receiveNoWait());
assertNull(consumer.receiveNoWait());
}
示例4: testRemoveNotScheduled
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
@Test
public void testRemoveNotScheduled() throws Exception {
Connection connection = createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the Browse Destination and the Reply To location
Destination management = session.createTopic(ScheduledMessage.AMQ_SCHEDULER_MANAGEMENT_DESTINATION);
MessageProducer producer = session.createProducer(management);
try {
// Send the remove request
Message remove = session.createMessage();
remove.setStringProperty(ScheduledMessage.AMQ_SCHEDULER_ACTION, ScheduledMessage.AMQ_SCHEDULER_ACTION_REMOVEALL);
remove.setStringProperty(ScheduledMessage.AMQ_SCHEDULED_ID, new IdGenerator().generateId());
producer.send(remove);
} catch (Exception e) {
fail("Caught unexpected exception during remove of unscheduled message.");
}
}
示例5: testSchedule
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
public void testSchedule() throws Exception {
Connection connection = createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
final long time = 1000;
ProducerThread producer = new ProducerThread(session, destination) {
@Override
protected Message createMessage(int i) throws Exception {
Message message = super.createMessage(i);
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time);
return message;
}
};
producer.setMessageCount(200);
producer.setDaemon(true);
producer.start();
Thread.sleep(5000);
}
示例6: offer
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
@Override
public boolean offer(T event) throws IvoryException {
Session session;
try {
session = getSession();
TextMessage msg = session.createTextMessage(event.toString());
msg.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY,
event.getDelay(TimeUnit.MILLISECONDS));
msg.setStringProperty("TYPE", event.getType().name());
producer.send(msg);
LOG.debug("Enqueued Message:" + event.toString() + "with delay "
+ event.getDelay(TimeUnit.MILLISECONDS) + " milli sec");
return true;
} catch (Exception e) {
LOG.error("Unable to offer event:" + event + " to activeMqueue", e);
throw new IvoryException("Unable to offer event:" + event + " to activeMqueue", e);
}
}
示例7: offer
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
@Override
public boolean offer(T event) throws FalconException {
Session session;
try {
session = getSession();
TextMessage msg = session.createTextMessage(event.toString());
msg.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY,
event.getDelay(TimeUnit.MILLISECONDS));
msg.setStringProperty("TYPE", event.getType().name());
producer.send(msg);
LOG.debug("Enqueued Message:" + event.toString() + "with delay "
+ event.getDelay(TimeUnit.MILLISECONDS) + " milli sec");
return true;
} catch (Exception e) {
LOG.error("Unable to offer event:" + event + " to activeMqueue", e);
throw new FalconException("Unable to offer event:" + event + " to activeMqueue", e);
}
}
示例8: sendMessageDelay
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
/**
* 延迟发送对象消息
* @param jmsTemplate
* @param destination
* @param objectMessage
* @param delay
*/
public static void sendMessageDelay(JmsTemplate jmsTemplate, Destination destination, final Serializable objectMessage, final long delay) {
jmsTemplate.send(destination, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
ObjectMessage om = session.createObjectMessage(objectMessage);
om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1 * 1000);
om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
return om;
}
});
}
示例9: send
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
/**
* 发送延迟消息
* @param msg
* @param delay
*/
public void send(String msg, long delay) {
_log.info("发送MQ延时消息:msg={},delay={}", msg, delay);
jmsTemplate.send(this.payNotifyQueue, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage tm = session.createTextMessage(msg);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1*1000);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
return tm;
}
});
}
示例10: send
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
public void send() {
template.send(this.destination, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage message=session.createTextMessage();
System.out.println("发出消息,延时10秒.");
String msgId=message.getJMSMessageID();
System.out.println("msgId:"+msgId);
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, 20*1000);
message.setStringProperty("content", "内容content...");
return message;
}
});
}
示例11: toMessage
import org.apache.activemq.ScheduledMessage; //导入依赖的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");
}
}
示例12: send
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
public void send(){
jmsTemplate.send(notifyQueue,new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage message=session.createTextMessage("textMsg....柯远");
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, 65*1000);
System.out.println("等65秒后再发");
return message;
}
});
}
示例13: send
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
/**
* 发送延迟消息
* @param msg
* @param delay
*/
public void send(String msg, long delay) {
_log.info("发送MQ延时消息:msg={},delay={}", msg, delay);
jmsTemplate.send(this.transNotifyQueue, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage tm = session.createTextMessage(msg);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1*1000);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
return tm;
}
});
}
示例14: send
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
/**
* 发送延迟消息
* @param msg
* @param delay
*/
public void send(Queue queue, String msg, long delay) {
_log.info("发送MQ延时消息:msg={},delay={}", msg, delay);
jmsTemplate.send(queue, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage tm = session.createTextMessage(msg);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1*1000);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
return tm;
}
});
}
示例15: send
import org.apache.activemq.ScheduledMessage; //导入依赖的package包/类
/**
* 发送延迟消息
* @param msg
* @param delay
*/
public void send(String msg, long delay) {
_log.info("发送MQ延时消息:msg={},delay={}", msg, delay);
jmsTemplate.send(this.refundNotifyQueue, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage tm = session.createTextMessage(msg);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1*1000);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
return tm;
}
});
}