Giter VIP home page Giter VIP logo

camel-pubsub's Introduction

Publish-subscribe in Apache Camel

If you'd like to use publish-subscribe pattern in Apache Camel application, you should not use the suggested seda:queue?multipleConsumers=true approach, described here. There is a "by design" flaw that may cost you a lot.

  from("seda:queue?multipleConsumers=true")
    .bean(Processor1)

  from("seda:queue?multipleConsumers=true")
    .bean(Processor2)

multipleConsumers implementation makes use of multicast and parallelProcessing under the hood and this combination utilizes the default thread pool to dispatch exchanges to the underlying endpoints. The problem here is that every subscriber becomes parallel implicitly. You didn't expect it, but there will be several threads running Processor1 concurrently and several threads running Processor2 concurrently as well.

Hence, if you have inner state inside either of them which relies on the order of incoming exchanges – you are in trouble.

By the way, this could be a bigger surprise if you had only one subscriber for some time and everything was working. It may (suddenly) break when you add another one.

Demonstration

This project is a simple demonstration of this behavior - review it, look into the comments and try to run:

$ sbt
> run -ac routes.xml

Bug report

The bug report is here.

The Camel team will not fix it, they claimed this behavior is "as designed".

Workarounds

threads(1) – NO

You would probably want to make execution sequential:

  from("seda:queue?multipleConsumers=true")
    .threads(1)
    .bean(Processor1)

This will not help, b/c this whole fragment gets called concurrently.

direct:seq – NO

  from("seda:queue?multipleConsumers=true")
    .to("direct:seq")

  from("direct:seq")
    .bean(Processor1)

This will make execution sequential, but it cannot guarantee the order of exchanges is intact.

Disruptor – YES

What seems the real fix is using Disruptor component, see the PR for required changes. Fetch the branch and try running it.

camel-pubsub's People

Contributors

alaz avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.