PageRenderTime 25ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/cmt/src/main/java/org/jboss/as/quickstarts/cmt/mdb/HelloWorldMDB.java

https://gitlab.com/avinashmx/WildFly
Java | 60 lines | 28 code | 5 blank | 27 comment | 2 complexity | 60de55ad4b34f8698f4df03027e679a8 MD5 | raw file
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
  4. * contributors by the @authors tag. See the copyright.txt in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.jboss.as.quickstarts.cmt.mdb;
  18. import java.util.logging.Logger;
  19. import javax.ejb.ActivationConfigProperty;
  20. import javax.ejb.MessageDriven;
  21. import javax.jms.JMSException;
  22. import javax.jms.Message;
  23. import javax.jms.MessageListener;
  24. import javax.jms.TextMessage;
  25. /**
  26. * <p>
  27. * A simple Message Driven Bean that asynchronously receives and processes the messages that are sent to the queue.
  28. * </p>
  29. *
  30. * @author Serge Pagop (spagop@redhat.com)
  31. *
  32. */
  33. @MessageDriven(name = "HelloWorldMDB", activationConfig = {
  34. @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
  35. @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/CMTQueue"),
  36. @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
  37. public class HelloWorldMDB implements MessageListener {
  38. private final static Logger LOGGER = Logger.getLogger(HelloWorldMDB.class.toString());
  39. /**
  40. * @see MessageListener#onMessage(Message)
  41. */
  42. public void onMessage(Message rcvMessage) {
  43. TextMessage msg = null;
  44. try {
  45. if (rcvMessage instanceof TextMessage) {
  46. msg = (TextMessage) rcvMessage;
  47. LOGGER.info("Received Message: " + msg.getText());
  48. } else {
  49. LOGGER.warning("Message of wrong type: " + rcvMessage.getClass().getName());
  50. }
  51. } catch (JMSException e) {
  52. throw new RuntimeException(e);
  53. }
  54. }
  55. }