• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Lazy initialize the JMS listener

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:

One part of my application is listening to a topic for refreshing my cache.

But suppose the server which is publishing the message is down. I still want my application to come up.
I tried to set lazy-int = true and then after the context is loaded tried to do context.getBean("testUpdateListener") thinking it will initialize the bean and it will start listening.
But it does not work. The listener does not start listening.

What is the best way to achieve this?

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off, for listeners. Why aren't you using the jms namespace. So your config is as simple as



lazy-init has nothing to do with starting or shutting down a listener container. It is only about when Spring instantiates an object. And for me, I would never ever use lazy-init in my configuration. I want everything created up front.
It is better for memory, heap, also telling me about errors earlier which reduces my costs to find bugs.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, and you should also use the jee namespace for jndi lookups. It has a lookup tag

I personally would put the jndi environment values into a jndi.properties file and place it in the root of my classpath.

<jee:jndi-lookup id="connectionFactory" jndi-name="x.TopicFactory"/>

Mark
 
Karan Jain
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark for the response. I will try to implement using those namespaces.

But my requirement is to load the context even if my listener fails.

As there are other services which needs loading even the cache refresh does not work.

How can I achieve that?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even with lazy init you would still have this problem.

If you don't have the listener, how will your application still be able to run. What if it still isn't up when a user needs it?

You could do some tricks, like parent child application contexts. Where you put yours listener into its own application context. When you create it in code, wrap it in a try-catch. Maybe even run that code in a separate thread that keeps running every 10 minutes until the listener is up, then after that application context is created stop running that job. And pass the other application context to the constructor to be the parent. Now it might need to be reversed because child application contexts can see beans in the parent, but not the other way around.

There might be another solution that I am not aware of.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic