方法postReceive
がorg.springframework.messaging.support.ChannelInterceptor
であるため、org.springframework.messaging.SubscribableChannel
では呼び出されません。 @StreamListener(Sink.INPUT)
の注釈付きメソッドの受信メッセージをすべて傍受する方法はありますか?例えばSpring Cloud Stream SubscribableChannelの受信メッセージを傍受する
:メッセージインターセプト
は前handle
方法以下
@StreamListener(Sink.INPUT)
public void handle(Foo foo) {
// ...
}
春クラウドストリームバインダーは、あなたのリスナーを上呼び出すDirectChannel
で
public interface EventSink {
String INPUT1 = "input1";
String INPUT2 = "input2";
@Input(INPUT1)
SubscribableChannel input1();
@Input(INPUT2)
SubscribableChannel input2();
}
public interface EventSource {
String OUTPUT1 = "output1";
String OUTPUT2 = "output2";
@Output(OUTPUT1)
MessageChannel output1();
@Output(OUTPUT2)
MessageChannel output2()';
}
spring:
cloud:
stream:
bindings:
input1:
destination: input1
input2:
destination: input2
output1:
destination: output1
output2:
destination: output2
public class EventHandler {
@StreamListener(EventSink.INPUT1)
public void handle(Foo1 foo) {
// ...
}
@StreamListener(EventSink.INPUT2)
public void handle(Foo2 foo) {
// ...
}
}
@Service
public class Bar1Service {
@Autowired
private EventSource source;
public void bar1() {
source.output1().send(MessageBuilder.withPayload("bar1").build());
}
}
@Service
public class Bar2Service {
@Autowired
private EventSource source;
public void bar2() {
source.output2().send(MessageBuilder.withPayload("bar2").build());
}
}
インターセプター?あなたは 'preSend()'を傍受することができます。 –
私はヘッダーからいくつかの情報を抽出して準備し、それらをThreadLocalに格納したいと思います。私は 'preSend'が出力のためだと考えました。 – user1831877
'preSend()'は適切ですが、私の答えを見てください。 –