-
Notifications
You must be signed in to change notification settings - Fork 22
Configuration Examples
业余布道师 edited this page Nov 1, 2018
·
7 revisions
MQProducerDemo
public class MQProducerDemo extends MQProducerAdapter<String> {
@Override
protected String doSend(String message) throws MQException {
return message;
}
}MQMessageEncoderDemo
public class MQMessageEncoderDemo implements MQMessageEncoderAdapter<String> {
@Override
public byte[] encode(String message) throws MQException {
return message.getBytes();
}
}MQConsumerDemo
public class MQConsumerDemo extends MQConsumerAdapter<String> {
@Override
protected void doReceive(String message) throws MQException {
System.out.println(message);
}
}MQMessageDecoderDemo
public class MQMessageDecoderDemo implements MQMessageDecoderAdapter<String> {
@Override
public String decode(byte[] bytes) throws MQException {
return new String(bytes);
}
}MQProducerMain start after MQConsumerMain
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:/compatible/applicationContext-{type}-producer.xml"})
public class MQProducerMain {
@Autowired
private MQProducerDemo mqProducerDemo;
@Test
public void test() throws Exception {
for (int i = 0; i < 10; i++)
mqProducerDemo.send("Test Message " + i);
Thread.sleep(5000);
}
}MQConsumerMain start before MQProducerMain
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:/compatible/applicationContext-{type}-consumer.xml"})
public class MQConsumerMain {
@Test
public void test() throws Exception {
Thread.sleep(50000);
}
}Demo code example
ActiveMQ config example with Spring
Kafka config example with Spring
RocketMQ config example with Spring