简体   繁体   English

在 Java 中,如何从一个生产者向多个消费者发送连续数据?

[英]In Java, How to send continuous Data to multiple consumers from one producer?

Problem statement:问题陈述:

  1. I have one server which is continuously producing prices.我有一台服务器,它不断产生价格。 This code is written in Java with spring boot.这段代码写在 Java 和 spring 引导。
  2. I have multiples consumer servers / java programs which are running on different systems.我有多个在不同系统上运行的消费者服务器/java 程序。 Who will use prices which was produced by first producer server.谁将使用第一个生产者服务器生成的价格。

Question: In one milliseconds, I will produce around 300-400 prices (data).问题:在一毫秒内,我将产生大约 300-400 个价格(数据)。 So Which is the best way to transfer continuous data from one producer server to multiple consumer servers?那么,将连续数据从一个生产者服务器传输到多个消费者服务器的最佳方式是什么?

Data sice: hardly some kbs.数据 sice:几乎没有一些 kbs。

I researched on google and come to know some answers:我在谷歌上研究并知道了一些答案:

  1. I can create one kafka producer who will produce prices and will send prices on some topics where other kafka consumers will receive/consume the same price on the same topic.我可以创建一个 kafka 生产者,他将产生价格并发送某些主题的价格,而其他 kafka 消费者将在同一主题上接收/消费相同的价格。
  2. I can write prices in one database table and other consumers will read the prices from same table.我可以在一个数据库表中写入价格,而其他消费者将从同一个表中读取价格。
  3. I can use some cloud consept where I will post prices on some cloud platform and from their consumers programs will read the prices.我可以使用一些云概念,我将在一些云平台上发布价格,并从他们的消费者程序中读取价格。

So which is the better way from among three of us or if you have any other architecture so please help me in this.所以我们三个中哪个是更好的方法,或者如果您有任何其他架构,请帮助我。

Thanks in advance.提前致谢。

Go With kafka! Go 带卡夫卡!

  1. with kafka you can scale independently on your producer and consumer by Load.使用 kafka,您可以通过 Load 在您的生产者和消费者上独立扩展。 During server failover or deployments, it will resume using "offset".在服务器故障转移或部署期间,它将使用“偏移量”恢复。 if you plan to scale horizontally there is a nice concept of consumer groups.如果您计划横向扩展,则有一个很好的消费者群体概念。
  2. if u plan using a database u will need to address the below points as a developer.如果您计划使用数据库,您将需要作为开发人员解决以下问题。
  • Your consumers need to sync to the database at scheduled intervals.您的消费者需要按计划的时间间隔同步到数据库。
  • You need a mechanism to not consume the same data in horizontally scaled systems.您需要一种机制来不在水平扩展的系统中使用相同的数据。
  1. which cloud mechanism exactly?究竟是哪种云机制?
  • if as storage u will get same issues as 2.如果作为存储,您将遇到与 2 相同的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何用Java实现一个生产者,多个使用者和多个对象? - How to implement one producer , multiple consumers and multiple Objects in Java? 一个生产者,多个消费者 - One Producer, multiple Consumers BlockingQueue - 一个生产者多个消费者 - BlockingQueue - one producer multiple consumers Java一生产者和二消费者 - Java one producer and two consumers Java生产者-消费者-多个消费者 - Producer-Consumer in Java - Multiple Consumers 生产者 消费者问题 一生产者多消费者 java - Producer Consumer problem one producer many consumers java 如何将非并行流与并行流互连(一个生产者多个消费者) - How to interconnect non-parallel stream with parallel stream(one producer multiple consumers) 当应用程序中存在一个生产者和多个消费者时,apache kafka如何处理一致性 - How apache kafka handles consistency when one producer and multiple consumers exist in application 如何实现具有多个消费者和多个队列的消费者生产者 - How to implement consumer-producer with multiple consumers and multiple queues 哪个Java阻塞队列最适合多个生产者和单个或多个消费者场景? - Which Java blocking queue is best for multiple producer and single or multiple consumers scenarios?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM