这对我来说很好。。。
@SpringBootApplication
public class So46453364Application implements CommandLineRunner {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext ctx = SpringApplication.run(So46453364Application.class, args);
Thread.sleep(10_000);
ctx.close();
}
@Autowired
private JmsTemplate template;
@Override
public void run(String... arg0) throws Exception {
this.template.convertAndSend("foo", "foo", m -> {
m.setStringProperty("foo", "bar");
return m;
});
this.template.convertAndSend("foo", "foo", m -> {
m.setStringProperty("foo", "baz");
return m;
});
}
@JmsListener(destination = "foo", selector = "foo = 'bar'")
public void bar(Message in) {
System.out.println("bar: " + in);
}
@JmsListener(destination = "foo", selector = "foo = 'baz'")
public void baz(Message in) {
System.out.println("baz: " + in);
}
}
bar: ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:gollum.local-53472-1506533911909-4:3:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:gollum.local-53472-1506533911909-4:3:1:1, destination = queue://foo, transactionId = null, expiration = 0, timestamp = 1506533912140, arrival = 0, brokerInTime = 1506533912141, brokerOutTime = 1506533912144, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 1030, properties = {foo=bar}, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = foo}
baz: ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:gollum.local-53472-1506533911909-4:4:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:gollum.local-53472-1506533911909-4:4:1:1, destination = queue://foo, transactionId = null, expiration = 0, timestamp = 1506533912150, arrival = 0, brokerInTime = 1506533912150, brokerOutTime = 1506533912150, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 1030, properties = {foo=baz}, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = foo}