Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does Kafka Converts Order info to Invoice #5

Closed
pavankjadda opened this issue Jan 23, 2018 · 4 comments
Closed

How does Kafka Converts Order info to Invoice #5

pavankjadda opened this issue Jan 23, 2018 · 4 comments

Comments

@pavankjadda
Copy link

Hello,
I was going through the code and trying to understand it. In OrderService class, method fireOrderCreatedEvent has kafkaTemplate.send("order", order.getId() + "created", order); statement, which sends Order object to Kafka messaging system.

private void fireOrderCreatedEvent(Order order) {
		kafkaTemplate.send("order", order.getId() + "created", order);
	}

And in OrderKafkaListener class you have the following method

@KafkaListener(topics = "order")
	public void order(Invoice invoice, Acknowledgment acknowledgment) {
		log.info("Revceived invoice " + invoice.getId());
		invoiceService.generateInvoice(invoice);
		acknowledgment.acknowledge();
	}

How did Order object serialize or converted to Invoice object? I am kind of confused here. Does Kafka implement this? or we need to manually do it here.

@ewolff ewolff closed this as completed in 85f016c Jan 23, 2018
@pavankjadda
Copy link
Author

I saw your updated documentation. However, I still have some questions

  1. JSON serialization is flexible. So when an Order is deserialized into Invoice and Delivery just the needed data is read, How is this possible? I know they use the same topic, but no relation exists between Order and Invoice i.e foreign key
  2. Things become complex when if no such relation exists. Order data on Kafka consumed by Invoice and Shipping. Since there is no relation between Shipping and Invoice, Invoice may consume one Order object and shipping may consume different Order object. When the user pulls his order information, he may not see correct information.
    I looked at other implementations, they deserialized Order (in their case Car) object on another microservice. Am I missing something here?

@ewolff
Copy link
Owner

ewolff commented Jan 24, 2018

1 - The attributes in Order, Invoice and Delivery have the same names. So a serialized Order can be interpreted as an Invoice or a Delivery. The additional attributes are ignored.
2 - The Order has an ID that is also present in Invoice and Delivery. So there is a relation.

@pavankjadda
Copy link
Author

Got it. In large enterprise applications do you think it's a good idea to have the same id for all the Objects? Let's just say we have custom order id: ORD112-34-44847477 for Order and as per your implementation Invoice and Delivery will get the same ID which has ORD in it, which confuses users. I think it's better to have a unique id (invoice_id, delivery_id) for each object based on object/microservice name and have the ID attribute for relation. What do you think?

@ewolff
Copy link
Owner

ewolff commented Jan 24, 2018

You need to correlate orders to invoices and deliveries. I am not sure how that should be done if the invoice and delivery do not contain the id of the order. Note that there might still be an additional invoice or delivery id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants