Skip to content

Instantly share code, notes, and snippets.

@martinez099
Last active April 8, 2020 19:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save martinez099/f0ceae5931796640159b4a3d869d43e1 to your computer and use it in GitHub Desktop.
billing_created() handler subscribed to events:order in order_service.py
def billing_created(self, _item):
if _item.event_action != 'entity_created':
return
billing = json.loads(_item.event_data)
rsp = send_message('read-model', 'get_entity', {'name': 'order', 'id': billing['order_id']})
order = rsp['result']
if order['status'] != 'IN_STOCK':
return
order['status'] = 'CLEARED'
self.event_store.publish('order', create_event('entity_updated', order))
@martinez099
Copy link
Author

martinez099 commented Apr 8, 2020

This event handler is subscribed to billing events.

02 guard for the correct event
05 parse event topic, i.e. billing
06 get order for billing from read model
08 guard for the correct state
11 set new order status
12 publish updated event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment