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

Publishing and subscribing with binding the same event class #271

Open
lc-apps-dev opened this issue Nov 26, 2021 · 1 comment
Open

Publishing and subscribing with binding the same event class #271

lc-apps-dev opened this issue Nov 26, 2021 · 1 comment

Comments

@lc-apps-dev
Copy link

lc-apps-dev commented Nov 26, 2021

Hello, with the following configuration inside my JEE app we jump into infinitive loop after emitting even one event with EventOne class.
This is due the binding the the same class for an exchange and for a queue.

		    ExchangeDeclaration testExchangeOne = declarerFactory()
	    		.createExchangeDeclaration("test.exchange.one")
	    		.withType(BuiltinExchangeType.DIRECT)
	    		.withAutoDelete(false)
	    		.withDurable(false); // (1)
	
		    QueueDeclaration testQueue = declarerFactory()
	    		.createQueueDeclaration("test.queue")
	    		.withAutoDelete(false)
	    		.withDurable(false)
	    		.withExclusiveAccess(false); // (2)
		    
		    BindingDeclaration bindingDeclaration = declarerFactory()
	    		.createBindingDeclaration(testQueue, testExchangeOne)
	    		.withRoutingKey("test.queue");
		
		    bind(EventOne.class)
	      		.toExchange("test.exchange.one")
	      		.withDeclaration(testExchangeOne)
	      		.withDeclaration(bindingDeclaration)
	      		.withDeclaration(testQueue)
	      		.withRoutingKey("test.queue"); // (3)
		    
		    bind(EventOne.class)
		      .toQueue("test.queue")
		      .autoAck();  // (4)

Simple solution is to create a copy of EventOne class properties into class with different name and bind it to the queue.

		    bind(EventOne.class)
	      		.toExchange("test.exchange.one")
	      		.withDeclaration(testExchangeOne)
	      		.withDeclaration(bindingDeclaration)
	      		.withDeclaration(testQueue)
	      		.withRoutingKey("test.queue"); // (3)
		    
		    bind(EventOneClone.class)
		      .toQueue("test.queue")
		      .autoAck();  // (4)

But this leads to code duplication for every event type, DRY principle violated.
Can You suggest any solution for that?
Many thanks for Your help!

@reinhapa
Copy link
Owner

I do not have a good solution of the top of my head at the moment. The is no way to distinguish between incoming and outgoing events when having the same Type for both directions. Any idea to solve this problem and enhance the implementation are appreciated. 😊

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