Announcement Announcement Module
Collapse
No announcement yet.
Inject a reference to the notifications message channel in batch listener Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inject a reference to the notifications message channel in batch listener

    Greeting :-)

    According with the spring-xd documentation, in Retrieve job notifications section, I need to create my own Batch listener and directly inject a reference to the notifications message channel in order to customize behaviour.


    I created the following listener:

    Code:
    public class MyListener implements JobExecutionListener {
    
        private SubscribableChannel channel;
    
        public void setChannel(SubscribableChannel channel) {
            this.channel = channel;
        }
    
        public void beforeJob(JobExecution jobExecution) {
    
        }
    
        public void afterJob(JobExecution jobExecution) {
            System.out.println("Testing 1");
            channel.send((Message<?>) jobExecution);
        }
    }


    And the following xml configuration:

    Code:
        <batch:job id="job">
            <batch:step id="helloSpringXDStep">
                <batch:tasklet ref="helloSpringXDTasklet" />
            </batch:step>       
            <batch:listeners>
                <batch:listener ref="myListener"/>
            </batch:listeners>
        </batch:job>
    
        <!--<beans profile="xd.jobExecutionListener">-->
            <!--<bean id="xd.jobExecutionListener" class="org.springframework.xd.dirt.plugins.job.support.listener.SimpleXdJobExecutionListener">-->
                <!--<constructor-arg index="0" ref="xd.job.jobExecutionEvents"/>-->
                <!--<constructor-arg index="1" ref="xd.job.aggregatedEvents"/>-->
            <!--</bean>-->
            <!--<int:publish-subscribe-channel id="xd.job.jobExecutionEvents" />-->
        <!--</beans>-->
    
        <bean id="myListener" class="org.springframework.springxd.samples.batch.MyListener">
            <property name="channel" ref="xd.job.jobExecutionEvents"/>
        </bean>
    
        <bean id="helloSpringXDTasklet"
            class="org.springframework.springxd.samples.batch.Hello1" />
    The commented code is a copy paste from spring-xd source code. I tried to reference with "xd.job.jobExecutionEvents" and with "xd.job.aggregatedEvents" however I'm getting a NoSuchBeanDefinitionException for both references when creating the job. What reference is the documentation talking about?

    Thank you
    Bruno

  • #2
    Sorry for the delay. We are in the process of moving to Stack Overflow as our "forum": http://stackoverflow.com/questions/tagged/spring-xd

    However, I do want to point out that we now provide simple support for adding a TAP anywhere you may want to listen to job events:
    https://github.com/spring-projects/s...-notifications

    If you have any further questions, please post on SO.

    Comment

    Working...
    X