DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Handling ActiveMQ disconnects in Camel CXF Routes: Part 2

Handling ActiveMQ disconnects in Camel CXF Routes: Part 2

Heath Kesler user avatar by
Heath Kesler
·
Jun. 09, 12 · Java Zone · Interview
Like (0)
Save
Tweet
5.43K Views

Join the DZone community and get the full member experience.

Join For Free
So previously I showed you how to setup error handling when working with Activemq from a CXF endpoint.  So that is fine, but what if you need ActiveMQ to be asynchronous?  CXF will define the route as synchronous, meaning ExchangePattern = InOut.  This will force the route to be synchronous, and therefore wait on a reply from the queue..... much like I spelled out in part 1.

But what if we need ActiveMQ to be asynchronous?  Seems easy, just change the exchange pattern to be InOnly for the ActiveMQ call like so:
.inOnly("activemq:queue.test")
So now your route returns much faster since it is not waiting on a reply from the ActiveMQ endpoint.  Cue the angels.......  but wait, what happens when we still need the error handling to catch the JMSException and return a predefined response if..... lets say.... ActiveMQ is down? 

With the ExchangePattern set to InOnly, you will see in SOAPUI that you just get an empty soap message.  So what happened to the predefined response?  If you have logging in you processor or bean that loads the response, you will see that it is still hitting your code, but it is not return the response for some reason.

THE REASON:
The reason is you have an ExchangePattern of InOnly set when you run the onException code, this is causing the camel route to return before your processor is finished processing.  So your exception processing does not effect the return to the CXF endpoint.

THE SOLUTION: you need to specify the onException portion of your route to be InOut using the following:
.onException(Exception.class).handle(true).setExchangePattern(ExchangePattern.InOut).processRef(myProcessor)
Now you should see your processor defined response from the onException getting passed back to the endpoint.
Processing Bean (software) Spring Framework

Published at DZone with permission of Heath Kesler, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Use Geofences for Precise Audience Messaging
  • Testing Schema Registry: Spring Boot and Apache Kafka With JSON Schema
  • A Guide to Understanding Vue Lifecycle Hooks
  • Ultra-Fast Microservices in Java: When Microstream Meets Open Liberty

Comments

Java Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo