Sigismund Dijkstra
Sigismund Dijkstra

Reputation: 41

How to add custom StartupListener to Camel Context via Spring

How to add custom StartupListener to Camel Context via Spring?

It sounds very easy (like adding ShutdownStrategy), but I found it very difficult. There is nothing about it here: http://camel.apache.org/advanced-configuration-of-camelcontext-using-spring.html

Thanks.

Upvotes: 2

Views: 2954

Answers (2)

Sigismund Dijkstra
Sigismund Dijkstra

Reputation: 41

Thanks Claus and Robert. I'm answering to my question to present solution.

Indeed EventNotifier may be used instead of StartupListener, althought it would much easier just to have StartupListener working as expected :) Anyway, the following code works like a charm:

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;
    }
}

And Spring: <bean id="startStopEmailEventNotifier" class="com....StartStopEmailEventNotifier"></bean>

Upvotes: 2

Robert Budźko
Robert Budźko

Reputation: 183

On the first glance this thread might be irrelevant but it's the same question as yours but in different purpose. Looks like based on pointed discussion JIRA ticket has been created.

Note that in pointed thread workaround can be found :).

Upvotes: 0

Related Questions