2

Can I create a pub/sub message message queue with RxJS inside angulajs application. I have for example two modules: ModuleA ModuleB They exists as separate npm package but connected in ModuleC - it's the main shell.

I don't want to create a dependency as ModuleD and create a tight coupling between the modules. So my thought is to create a message bus using RxJS. Is it possible?

I presume an API will look like that: RxQueue.subscribe("name:of:the:queuemessage", handler => { handler.result } ); RxQueue.create("name:of:the:queuemessage", (observer) => { // implementation of usual Rx subscribtion })

hackp0int
  • 4,052
  • 8
  • 59
  • 95

2 Answers2

1

I think this might be closest to what you are asking for:

rxmqjs/rxmq.js: JavaScript pub/sub library based on RxJS
https://github.com/rxmqjs/rxmq.js
https://www.npmjs.com/package/rxmq

Not angular specific, but I consider that a good thing.

Tom
  • 17,103
  • 8
  • 67
  • 75
0

It might not be exactly what you are looking for but for sharing state and data between different components and modules, you could use redux/ngrx-store.

Redux is an architecture in which you can send state to a store. The store will update itself and notify everyone listening to it if something has changed.

So your modules could both subscribe to the store and listen to events. If they want to communicate, they could send a message to the store. The store would then notify everyone listening if something has changed. One difference is that this store object will actually store this object as a temp database would. This isn't really queue behaviour.

Checkout http://redux.js.org/ for more information.

KwintenP
  • 4,637
  • 2
  • 22
  • 30
  • Hi, thanks for the answer - But I actually looking for a queue behavior. I was considering a redux implementation but's to overhead for my concrete implementation. And using it with angularjs (ng1) it's actually redundant. But I will reconsider it if you will be able to show me a good working example. Of course if it's not a hassle for you mate. – hackp0int Oct 11 '16 at 15:32