मेरे पास वसंत एकीकरण प्रवाह है जिसमें एसिंक निष्पादन शामिल है, गेटवे से नियंत्रक तक मूल्य लौटा रहा है, मूल्य लौटने के बाद निरंतर एकीकरण प्रवाह है। यहाँवसंत एकीकरण प्रवाह में प्रथाओं को संभालने में त्रुटि
@MessagingGateway
public interface GW {
@Gateway(requestChannel = "f.input")
Task input(Collection<MessengerIncomingRequest> messages);
}
और प्रवाह है:
यहाँ प्रवेश द्वार है
@Bean
IntegrationFlow jFlow() {
return IntegrationFlows.from(
MessageChannels.executor("f.input", executor()))
.split()
.channel(MessageChannels.executor(executor()))
.transform(transformer)
.channel(routerChannel())
.get();
}
@Bean
ThreadPoolTaskExecutor executor() {
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
...
return pool;
}
@Bean
MessageChannel routerChannel() {
return MessageChannels
.publishSubscribe("routerChannel", executor())
.get();
}
@Bean
IntegrationFlow routerChannelFlow() {
return IntegrationFlows
.from(routerChannel())
.publishSubscribeChannel(s -> s
.subscribe(f -> f.bridge(null))
.subscribe(process()))
.get();
}
@Bean
IntegrationFlow process() {
return f ->
f.route(p -> p.getKind().name(),
m -> m.suffix("Channel")
.channelMapping(TaskKind.CREATE.name(), "create")
....
}
@Bean
IntegrationFlow createFlow() {
return IntegrationFlows.from(
MessageChannels.direct("createChannel"))
.handle(routerService)
.get();
}
मैं पूरी प्रवाह के लिए एक त्रुटि हैंडलर को कैसे परिभाषित कर सकते हैं? सर्वोत्तम प्रथाएं क्या हैं? मुझे पता है कि मैं गेटवे विधि कॉल के लिए एक कोशिश/पकड़ ब्लॉक डाल सकता हूं, लेकिन यह channel(routerChannel())
से पहले आने वाली सभी चीज़ों के लिए केवल jFlow
प्रवाह में अपवादों को पकड़ लेगा।
मैं बाकी प्रवाह के लिए त्रुटियों को कैसे संभाल सकता हूं? या पूरे प्रवाह के लिए?
अद्यतन
मैं publishSubscribeChannel
@Bean
IntegrationFlow routerChannelFlow() {
return IntegrationFlows
.from(routerChannel())
.publishSubscribeChannel(s -> s
.subscribe(f -> f.bridge(null))
.subscribe(process())
.errorHandler(errorHandler))
.get();
}
के लिए त्रुटि हैंडलर जोड़ा है, लेकिन यह क्योंकि अपवाद मैं निम्नलिखित त्रुटि मिलती है के मामले में, मदद करने के लिए प्रतीत नहीं होता:
cMessagingTemplate$TemporaryReplyChannel : Reply message received but the receiving thread has already received a reply:ErrorMessage [payload=org.springframework.messaging.MessageHandlingException:
और मेरी त्रुटि हैंडलर को कॉल नहीं किया जाता है।
अद्यतन
गैरी के जवाब के अनुसार मैं इस कोड की कोशिश की:
@Bean
IntegrationFlow jFLow() {
return IntegrationFlows.from(
MessageChannels.executor("f.input", executor()))
.split()
.channel(MessageChannels.executor(executor()))
.transform(transformer)
.channel(routerChannel())
.get();
}
@Bean
IntegrationFlow exceptionOrErrorFlow() {
return IntegrationFlows.from(
MessageChannels.direct("exceptionChannel"))
.handle(errorHandler, "handleError")
.get();
}
@Bean
MessageChannel exceptionChannel() {
return MessageChannels.direct("exceptionChannel")
.get();
}
@Bean
IntegrationFlow process() {
return f ->
f.enrichHeaders((spec) ->
spec.header("errorChannel", "exceptionChannel", true))
f.route(p -> p.getKind().name(),
m -> m.suffix("Channel")
.channelMapping(TaskKind.CREATE.name(), "create")
....
}
@MessagingGateway(errorChannel = "exceptionChannel")
एक और संपादित मैं प्रवेश द्वार के लिए exceptionChannel
जोड़ा के बाद, और दूसरे चरण के लिए शीर्ष लेख को समृद्ध चले गए (async) मेरे प्रवाह का। प्रवाह के सिंक्रोनस हिस्से में अपवाद फेंकने पर भी नियंत्रक अवरुद्ध हो जाता है।
गैरी, भयानक स्पष्टीकरण के लिए धन्यवाद! मैं कुछ चीजों को स्पष्ट करना चाहता हूं * 1। 'ग्रीनवे द्वारा स्थापित किया गया त्रुटि चैनल हेडर को प्रतिस्थापित करने के लिए .enrichHeaders का उपयोग करें (सत्य को ओवरराइट सेट करना सुनिश्चित करें)। * * - मुझे किस चैनल नाम से प्रतिस्थापित करना चाहिए? * 2। 'स्पष्ट रूप से एक डिफ़ॉल्ट एरर चैनल सेट * * - क्या आप कृपया इस संकेत को दे सकते हैं कि बीन/क्लास को यह डिफ़ॉल्ट IrrorChannel सेट करना चाहिए? इसे कहीं भी नहीं मिला। –
मुझे लगता है कि मैं समझ गया कि आपका क्या मतलब है, मैंने तदनुसार मेरा जवाब अपडेट किया है, अभी भी कुछ मुद्दे हैं, लेकिन मुझे लगता है कि मैं सुरंग के अंत में प्रकाश देखता हूं। –
मेरा संपादन देखें - आप जल्द ही हेडर बदल रहे हैं। –