8

What are the advantages of using DefaultJmsListenerContainerFactory over DefaultMessageListenerContainer ?

  • If i configure DMLC directly , i do get a handle to check the status by calling isRunning(). Also i do get a facility to start and stop the DMLC

  • However, per new spring specs, if i configure DefaultJmsListenerContainerFactory , i do not get handle of DMLC, so i am unable to do any of above operations.

So looking at above limitation, can somebody explain why one should use DefaultJmsListenerContainerFactory over DMLC

Also, if i use DefaultJmsListenerContainerFactory , what are the ways to achive above functionality?

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
user3534483
  • 2,133
  • 5
  • 22
  • 19

1 Answers1

8

The factory was introduced to support the creation of listener containers for @JmsListener annotated POJO methods.

If you are not using that mechanism, you can continue to define your DLMC directly.

EDIT

When using @JmsListener, the containers are not registered as beans themselves, but are available using the registry bean; you can get a reference to the container so you can start/stop etc.

See the javadocs for the JmsListenerEndpointRegistry for how to get references to the containers either individually by id, or all.

EDIT2

I am not sure what you mean in comment 3; the registry has all containers, regardless of which container factory was used to create the container...

@JmsListener(id="foo", destination="foo", containerFactory="one")
public void listen1(String payload) {
    System.out.println(payload + "foo");
}

@JmsListener(id="bar", destination="bar", containerFactory="two")
public void listen2(String payload) {
    System.out.println(payload + "bar");
}

If you are using configureListenerContainers() to programmatically create endpoints, you have to provide them with containers not container factories.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I am using @JmsListener ...However in that case also there should be some handle to start and stop the listener manually – user3534483 Oct 30 '15 at 01:05
  • I tried above approach and it worked. However, in my application i am going to create two instances of DefaultJmsListenerContainerFactory as i have two diff QM. In that case, how can i add two factories from configureJmsListeners method? – user3534483 Oct 31 '15 at 05:29
  • See my next edit. It's generally better to ask a new question rather than commenting on a closed one. – Gary Russell Oct 31 '15 at 14:28