Created
March 30, 2013 22:50
-
-
Save tadas-subonis/5278699 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderPlacedEvent { | |
private Order order; | |
} | |
class ShopSellerService { | |
@Inject | |
private EventBus eventBus; | |
public void sell(Order order) { | |
order.toPlaced(); | |
eventBus.publish(new OrderPlacedEvent(order)); | |
} | |
} | |
class SmsNotifier { | |
@Inject | |
private EventBus eventBus; | |
@Inject | |
private SmsGateway smsGateway; | |
@Listener | |
public void listen(OrderPlacedEvent event) { | |
Template message = TemplateFactory.createOrderPlacedMessage(); | |
/* | |
* Infer destination customer and other variables for template | |
*/ | |
Message message = message.assign(event.getOrder()); | |
smsGateway.send(message); | |
} | |
@PostConstruct | |
public void loaded() { | |
/* | |
* After the bean has been initialized we start listening for events on event bus. | |
* There is no need to unsubscribe on PreDestroy because we assume this will get called | |
* when the whole application is stopped - this listener is application scoped. | |
*/ | |
eventBus.subscribe(this); | |
} | |
} | |
class WarehouseJobUpdator { | |
@Inject | |
private EventBus eventBus; | |
@Inject | |
private JmsGateway jmsGateway; | |
@Listener | |
public void listen(OrderPlacedEvent event) { | |
/* | |
* Forward message to Warehouse JMS queue | |
*/ | |
jmsGateway.sendToWarehouse(event); | |
} | |
@PostConstruct | |
public void loaded() { | |
eventBus.subscribe(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment