Spring Reactor - it's out - and here's a brief sample
Spring Reactor is out (http://www.springsource.org/node/22606) and here's my first shot at using it with the annotations;https://github.com/willschipp/spring-reactor-annotations
here's our domain object;
package de.incompleteco.spring.reactor.domain; import java.io.Serializable; import java.util.Date; public class LogEvent implements Serializable { private static final long serialVersionUID = 1L; private String source; private Date timestamp; private String message; public String getSource() { return source; } public void setSource(String source) { this.source = source; } public Date getTimestamp() { return timestamp; } public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } @Override public String toString() { return "LogEvent [source=" + source + ", timestamp=" + timestamp + ", message=" + message + "]"; } }
here's the class that's going to do all the work. that is, it will process the event given to it by Reactor;
package de.incompleteco.spring.reactor.command; import reactor.fn.Consumer; import reactor.fn.Event; import reactor.spring.context.annotation.On; import de.incompleteco.spring.reactor.domain.LogEvent; public class SimpleLogEventConsumer implements Consumer < Event < LogEvent > > { @On(reactor="log.event.reactor",selector="log.event") public void accept(Event < LogEvent > event) { System.out.println(Thread.currentThread().getId() + " " + event.getData()); } }
and here's the configuration for it (using @Configuration)
package de.incompleteco.spring.reactor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import reactor.core.Reactor; import reactor.fn.Consumer; import reactor.fn.Event; import reactor.spring.context.ConsumerBeanPostProcessor; import reactor.spring.context.ReactorFactoryBean; import de.incompleteco.spring.reactor.command.SimpleLogEventConsumer; import de.incompleteco.spring.reactor.domain.LogEvent; @Configuration public class AppConfig { @Bean public Reactor reactor() throws Exception { ReactorFactoryBean factory = new ReactorFactoryBean(); factory.setName("log.event.reactor"); //return return factory.getObject(); } @Bean public Consumer> consumer() { return new SimpleLogEventConsumer(); } @Bean public ConsumerBeanPostProcessor consumerBeanPostProcessor() { return new ConsumerBeanPostProcessor(); } }
No comments:
Post a Comment