Watching All Events on an Event Bus
A fourth way of monitoring a bus is to watch all events using the UntypedEventListener
.
This option captures all events, including non-record events and lifecycle events for jobs and event buses
(when monitoring the system bus).
Here's the complete example using this approach.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | EventBus bus = EventBus.getSystemEventBus(); bus.addListener( null , new UntypedEventListener() { @Override public void onEvent(Event<?> event) { System.out.println( "event: " + event); } }); DataReader reader ; DataWriter writer; // write purchases to the bus under the "purchases" topic reader = new CSVReader( new File( "example/data/input/purchases.csv" )) .setFieldNamesInFirstRow( true ); writer = new EventBusWriter(bus, "purchases" ); Job job1 = new Job(reader, writer).runAsync(); // write calls to the bus under the "calls" topic reader = new CSVReader( new File( "example/data/input/call-center-inbound-call.csv" )) .setFieldNamesInFirstRow( true ); writer = new EventBusWriter(bus, "calls" ); Job job2 = new Job(reader, writer).runAsync(); job1.waitUntilFinished(); job2.waitUntilFinished(); bus.shutdown(); |
Here's some of the output you'd see running this example. You can see it captures both the lifecycle events and the different record events for all topics.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | event: com.northconcepts.datapipeline.job.JobLifecycleListener.onStart#null event: com.northconcepts.datapipeline.job.JobLifecycleListener.onStart#null event: com.northconcepts.datapipeline.eventbus.RecordListener.onRecord#calls event: com.northconcepts.datapipeline.eventbus.RecordListener.onRecord#purchases event: com.northconcepts.datapipeline.eventbus.RecordListener.onRecord#purchases event: com.northconcepts.datapipeline.eventbus.RecordListener.onRecord#purchases event: com.northconcepts.datapipeline.eventbus.RecordListener.onRecord#calls event: com.northconcepts.datapipeline.eventbus.RecordListener.onRecord#purchases event: com.northconcepts.datapipeline.job.JobLifecycleListener.onFinish#null ... event: com.northconcepts.datapipeline.eventbus.RecordListener.onRecord#purchases event: com.northconcepts.datapipeline.eventbus.RecordListener.onRecord#purchases event: com.northconcepts.datapipeline.job.JobLifecycleListener.onFinish#null event: com.northconcepts.datapipeline.eventbus.ShutdownListener.onShuttingDown#null event: com.northconcepts.datapipeline.eventbus.EventBusLifecycleListener.onShuttingDown#null |