Concurrent processing of single InputStream with independent consumers

后端 未结 3 1942
迷失自我
迷失自我 2021-02-15 23:48

I need to spawn N consumer threads, which process same InputStream concurrently, e.g - transform it somehow, calculate checksum or digital signature etc. These consumers do not

3条回答
  •  自闭症患者
    2021-02-16 00:30

    You can try some Java Messaging Service (JMS) implementation like Apache ActiveMQ.

    In your case you'd need to create a so called Topic (see Topics vs. Queues). A topic is created by the producer, and is published to N consumers, which may run concurrently, with each consumer receiving exactly the same data.

    Since you want to use InputStreams there is a chapter on how to send messages are streams.

    I suppose, typically, producers and consumers would be separate processes, probably running on different machines on the network. I think you can configure it to run completely in a single JVM, though. This would depend on the implementation of JMS. These are also quite famous: HornetQ by JBoss, RabbitMQ, and a whole bunch of others.

提交回复
热议问题