0
votes

I can receive pre-defined job Execution events for my spring xd job as follows:

xd>job create --name myHttpJob --definition "httpJob" --deploy
xd>stream create --name jobExecutionEvents --definition "tap:job:myHttpJob.job >log" --deploy

Reference: http://docs.spring.io/spring-xd/docs/1.0.3.RELEASE/reference/html/#_retrieve_job_notifications

However, I would like to fire my own custom event and be able to do something with it. So maybe create a my own custom jobExecution event and publish it or create a totally new custom event and new listener. I'm having trouble finding the best way to do this, my question is what is the best way to do this in Spring XD?

1

1 Answers

1
votes

It's not so easy to create a new tap for a custom event (you'd need a plugin to bind it to the bus).

However, you can easily add a listener to your job config and publish events to the aggregated events channel bean.

See https://github.com/spring-projects/spring-xd/blob/master/spring-xd-dirt/src/main/resources/META-INF/spring-xd/plugins/job/job-module-beans.xml

Only your events (and any others you enable) will go to the aggregated events channel.

If you want to explore adding your own tap, see https://github.com/spring-projects/spring-xd/blob/master/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/plugins/job/JobEventsListenerPlugin.java for how the standard channels are bound to the bus.

Of course, you could always have your listener publish to rabbit outside of the XD infrastructure, via an <int-amqp:outbound-channel-adapter/> from within your job configuration (but don't use a bus-based queue for that).

EDIT in response to your comment below.

I just tried it with Spring XD 1.1.0.RELEASE with no problems.

I added this

<int:inbound-channel-adapter expression="'foo'" channel="xd.job.aggregatedEvents">
    <int:poller fixed-delay="5000"/>
</int:inbound-channel-adapter>

to the timestampfile file job (added the int namespace too).

This sends the literal foo to the aggregated events channel.

I then did this...

xd:>job create --name jobxxx --definition timestampfile
Successfully created job 'jobxxx'
xd:>job deploy jobxxx
Deployed job 'jobxxx'
xd:>stream create foo --definition "tap:job:jobxxx > log" --deploy
Created and deployed new stream 'foo'

...and saw this on the console...

18:29:13,392  INFO xdbus.tap:job:jobxxx.a1de5739-4399-4186-94de-33c5290a8411-1 sink.foo - foo
18:29:18,388  INFO xdbus.tap:job:jobxxx.a1de5739-4399-4186-94de-33c5290a8411-1 sink.foo - foo
18:29:23,390  INFO xdbus.tap:job:jobxxx.a1de5739-4399-4186-94de-33c5290a8411-1 sink.foo - foo
18:29:28,390  INFO xdbus.tap:job:jobxxx.a1de5739-4399-4186-94de-33c5290a8411-1 sink.foo - foo