我正在使用 rabbitmq 。我已经定义了具有优先级的队列,但是当我必须发送具有优先级的消息时,我不知道如何在其上指定优先级。
这是我的代码
StreamProcessor.java
public interface StreamProcessor {
public static final String TEST_JOB_OUTPUT = "test-job-output";
@Output(StreamProcessor.TEST_JOB_OUTPUT)
MessageChannel testJobOutput();
}
MessageSender.java
@Autowired
@Qualifier(StreamProcessor.TEST_JOB_OUTPUT)
private MessageChannel testJobOutput;
public void sendMessage(String s, MessagePriority priority) {
testJobOutput.send(MessageBuilder.withPayload(s).build());
}
我尝试在邮件中指定标题“ x-priority”,但似乎不起作用。
public void sendMessage(String s, MessagePriority priority) {
testJobOutput.send(MessageBuilder.withPayload(s).setHeader("x-priority", 10).build());
}
答案 0 :(得分:0)
通过尝试和失败找到了解决方案...这是优先级而不是 x优先级
public class MessageSender {
public static final String MESSAGE_HEADER_PRIORITY = "priority";
@Autowired
@Qualifier(StreamProcessor.TEST_JOB_OUTPUT)
private MessageChannel testJobOutput;
public void sendMessage(String s, MessagePriority priority) {
testJobOutput.send(MessageBuilder.withPayload(s).setHeader(MESSAGE_HEADER_PRIORITY, priority.value()).build());
}
}