如何通過Spring將定製的StartupListener添加到Camel上下文中?如何通過Spring將定製的StartupListener添加到Camel上下文中
聽起來很簡單(就像添加ShutdownStrategy一樣),但是我發現它非常困難。 這裏沒什麼關於它的: http://camel.apache.org/advanced-configuration-of-camelcontext-using-spring.html
謝謝。
如何通過Spring將定製的StartupListener添加到Camel上下文中?如何通過Spring將定製的StartupListener添加到Camel上下文中
聽起來很簡單(就像添加ShutdownStrategy一樣),但是我發現它非常困難。 這裏沒什麼關於它的: http://camel.apache.org/advanced-configuration-of-camelcontext-using-spring.html
謝謝。
乍一看this thread可能是無關緊要的,但它與您的問題相同,但目的不同。看起來像基於尖銳的討論JIRA ticket已被創建。
請注意,在尖頭螺紋解決方法可以找到:)。
重寫Main對於如此簡單的目的太複雜了,我需要:)我只是想發送有關應用程序明星/停止的電子郵件通知。 –
由於可能在停止的情況下,恐怕它可能不可能開始。 –
謝謝克勞斯和羅伯特。我正在回答我的問題以提出解決方案。
事實上,事件通知可以用來代替StartupListener,althought它會更容易只是爲了有StartupListener按預期工作:) 無論如何,下面的代碼工作就像一個魅力:
public class StartStopEmailEventNotifier extends EventNotifierSupport {
@Override
public void notify(EventObject event) throws Exception {
try {
if (event instanceof CamelContextStartedEvent) {
//send start email notification
}
if (event instanceof CamelContextStoppingEvent) {
//send stop email notification
}
} catch (Exception e) {
LOG.error("Problem with sending email: ", e);
}
}
@Override
public boolean isEnabled(EventObject event) {
if (event instanceof CamelContextStartedEvent || event instanceof CamelContextStoppingEvent) {
return true;
}
return false;
}
}
春季:<bean id="startStopEmailEventNotifier" class="com....StartStopEmailEventNotifier"></bean>
你需要什麼StartupListener?您可以使用EventNotifier,它在駱駝啓動時爲您提供回調,並且它可以按照您提供的鏈接顯示。 –
只需發送有關應用程序啓動/停止的電子郵件通知。停止對ShutdownStrategy來說微不足道,但開始並不是那麼微不足道。讓我試試EventNotifier。 –