Java Code Examples for javax.jms.Message

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project human-task-poc-proposal, under directory /human-task-switchard/src/test/java/org/jboss/humantaskswitchyard/.

Source file: SwitchardCamelCDISimpleTest.java

  26 
vote

@Test public void sendTextMessageToJMSQueue() throws Exception {
  final TaskUserRequest payload=new TaskUserRequest(1,"salaboy");
  MessageConsumer notificationConsumer=createNotificationConsumer(NOTIFICATION_QUEUE_NAME);
  MessageConsumer notificationConsumer2=createNotificationConsumer(NOTIFICATION_QUEUE_NAME);
  sendOperationToQueue(payload,"activate",QUEUE_NAME);
  Thread.sleep(5000);
  Message message=notificationConsumer.receive(1000);
  assertNotNull(message);
  Message message2=notificationConsumer2.receive(1000);
  assertNotNull(message2);
  assertEquals(((ObjectMessage)message).getObject(),((ObjectMessage)message2).getObject());
  Thread.sleep(5000);
}
 

Example 2

From project fedora-client, under directory /fedora-client-messaging/src/main/java/com/yourmediashelf/fedora/client/messaging/.

Source file: JMSManager.java

  23 
vote

/** 
 * Allows the caller to send a Serializable object to a destination
 */
public void send(String destName,Serializable obj) throws MessagingException {
  JMSDestination jmsDest=getJMSDestination(destName);
  setupProducer(jmsDest);
  try {
    Message msg=createJMSMessage(obj,jmsDest.session);
    jmsDest.producer.send(msg);
  }
 catch (  JMSException e) {
    throw new MessagingException(e.getMessage(),e);
  }
  if (logger.isDebugEnabled()) {
    logger.debug("send() - message sent to destination " + destName);
  }
}
 

Example 3

From project hornetq-version-tests, under directory /src/test/java/org/objectweb/jtests/jms/conform/connection/.

Source file: ConnectionTestIT.java

  23 
vote

/** 
 * Test that a <code>MessageProducer</code> can send messages while a  <code>Connection</code> is stopped.
 */
public void testMessageSentWhenConnectionClosed(){
  try {
    senderConnection.stop();
    Message message=senderSession.createTextMessage();
    sender.send(message);
    receiver.receive(TestConfig.TIMEOUT);
  }
 catch (  JMSException e) {
    fail(e);
  }
}
 

Example 4

From project arquillian-showcase, under directory /spring/spring-jms/src/test/java/com/acme/spring/jms/impl/.

Source file: MessageSenderImplTestCase.java

  22 
vote

/** 
 * <p>Tests the  {@link MessageSenderImpl#sendMessage(String)} method.</p>
 * @throws Exception if any error occurs
 */
@Test public void testSend() throws Exception {
  String message="Hello world";
  messageSender.sendMessage(message);
  Message result=jmsTemplate.receive("SpringTestQueue");
  assertNotNull("The received message was null.",result);
  assertTrue("The received message had invalid type.",result instanceof TextMessage);
  assertEquals("The received message had invalid text.",message,((TextMessage)result).getText());
  System.out.println(((TextMessage)result).getText());
}
 

Example 5

From project arquillian_deprecated, under directory /examples/junit/src/test/java/com/acme/jms/.

Source file: InjectionTestCase.java

  22 
vote

@Test public void shouldBeAbleToSendMessage() throws Exception {
  String messageBody="ping";
  Connection connection=null;
  try {
    connection=factory.createConnection();
    Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
    QueueRequestor requestor=new QueueRequestor((QueueSession)session,dlq);
    connection.start();
    Message request=session.createTextMessage(messageBody);
    Message response=requestor.request(request,5000);
    Assert.assertEquals("Should have responded with same message",messageBody,((TextMessage)response).getText());
  }
  finally {
    connection.close();
  }
}
 

Example 6

From project blacktie, under directory /stompconnect-1.0/src/main/java/org/codehaus/stomp/jms/.

Source file: StompSession.java

  22 
vote

public void sendToJms(StompFrame command) throws JMSException, ProtocolException, NamingException, UnsupportedEncodingException {
  Map headers=command.getHeaders();
  String destinationName=(String)headers.remove(Stomp.Headers.Send.DESTINATION);
  Message message=convertFrame(command);
  Destination destination=convertDestination(destinationName,false);
  int deliveryMode=getDeliveryMode(headers);
  int priority=getPriority(headers);
  long timeToLive=getTimeToLive(headers);
  producer.send(destination,message,deliveryMode,priority,timeToLive);
  log.debug("Sent message: " + message.getJMSMessageID());
}
 

Example 7

From project capedwarf-blue, under directory /common/src/main/java/org/jboss/capedwarf/common/jms/.

Source file: ServletExecutorProducer.java

  22 
vote

/** 
 * Send jms message.
 * @param creator the message creator
 * @return msg id
 * @throws Exception for any error
 */
public String sendMessage(MessageCreator creator) throws Exception {
  final MessageProducer mp=getProducer();
  Message message=creator.createMessage(getSession());
  if (message == null) {
    message=getSession().createMessage();
    creator.enhanceMessage(message);
  }
  setString(message,"module",getModuleName());
  setString(message,"appId",Application.getAppId());
  setString(message,"path",creator.getPath());
  setString(message,"factory",creator.getServletRequestCreator().getName());
  mp.send(message);
  return message.getJMSMessageID();
}
 

Example 8

From project chukwa, under directory /src/test/java/org/apache/hadoop/chukwa/datacollection/adaptor/jms/.

Source file: TestJMSAdaptor.java

  22 
vote

public void testJMSTextMessage() throws Exception {
  JMSAdaptor adaptor=new JMSAdaptor();
  adaptor.parseArgs(DATA_TYPE,"vm://localhost -t test.topic",AdaptorManager.NULL);
  adaptor.start("id",DATA_TYPE,0,this);
  Message message=session.createTextMessage(MESSAGE_PAYLOAD);
  publisher.publish(message);
synchronized (this) {
    wait(1000);
  }
  assertEquals("Message not received",1,messagesReceived);
}
 

Example 9

From project components, under directory /jca/src/main/java/org/switchyard/component/jca/composer/.

Source file: JMSMessageComposer.java

  22 
vote

/** 
 * {@inheritDoc}
 */
@Override public JMSBindingData decompose(Exchange exchange,JMSBindingData target) throws Exception {
  getContextMapper().mapTo(exchange.getContext(),target);
  Message jmsMessage=target.getMessage();
  ObjectMessage targetObj=ObjectMessage.class.cast(jmsMessage);
  targetObj.setObject(exchange.getMessage().getContent(Serializable.class));
  return target;
}
 

Example 10

From project CamelInAction-source, under directory /chapter6/notify/src/test/java/camelinaction/.

Source file: OrderClient.java

  21 
vote

public void sendOrder(int customerId,Date date,String... itemIds) throws Exception {
  String d=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(date);
  String body=customerId + "," + d;
  for (  String id : itemIds) {
    body+="," + id;
  }
  Connection con=fac.createConnection();
  con.start();
  Session ses=con.createSession(false,Session.AUTO_ACKNOWLEDGE);
  Destination dest=ses.createQueue("order");
  MessageProducer prod=ses.createProducer(dest);
  prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
  Message msg=ses.createTextMessage(body);
  prod.send(msg);
  prod.close();
  ses.close();
  con.close();
}
 

Example 11

From project core_4, under directory /impl/src/main/java/org/richfaces/application/push/impl/jms/.

Source file: JMSTopicsContextImpl.java

  21 
vote

public synchronized void start() throws NamingException, JMSException {
  connection=createConnection();
  session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
  consumer=session.createConsumer(lookupTopic(),null,false);
  pollingThread=getThreadFactory().newThread(new Runnable(){
    public void run(){
      try {
        while (true) {
          Message message=consumer.receive();
          if (message != null) {
            String subtopicName=message.getStringProperty(SUBTOPIC_PROPERTY);
            TopicKey topicKey=new TopicKey(name,subtopicName);
            org.richfaces.application.push.Topic pushTopic=getOrCreateTopic(topicKey);
            if (pushTopic != null) {
              try {
                Object messageData=getMessageData(message);
                pushTopic.publish(topicKey,messageData);
              }
 catch (              Exception e) {
                LOGGER.error(e.getMessage(),e);
              }
            }
          }
 else {
            break;
          }
        }
      }
 catch (      JMSException e) {
        LOGGER.error(e.getMessage(),e);
      }
    }
  }
);
  pollingThread.start();
}
 

Example 12

From project droolsjbpm-integration, under directory /drools-pipeline/src/main/java/org/drools/runtime/pipeline/impl/.

Source file: JmsMessenger.java

  21 
vote

public void run(){
  while (this.run) {
    Message msg=null;
    try {
      msg=this.consumer.receive();
      if (msg != null) {
        if (this.resultHandlerFactory != null) {
          pipeline.insert(msg,this.resultHandlerFactory.newResultHandler());
        }
 else {
          pipeline.insert(msg,null);
        }
      }
    }
 catch (    JMSException e) {
      this.feeder.handleException(this.feeder,msg,e);
    }
  }
}
 

Example 13

From project james, under directory /queue-activemq/src/main/java/org/apache/james/queue/activemq/.

Source file: ActiveMQMailQueue.java

  21 
vote

@Override public List<Message> removeWithSelector(String selector) throws MailQueueException {
  List<Message> mList=super.removeWithSelector(selector);
  for (int i=0; i < mList.size(); i++) {
    Message m=mList.get(i);
    if (m instanceof ActiveMQBlobMessage) {
      try {
        ((ActiveMQBlobMessage)m).deleteFile();
      }
 catch (      Exception e) {
        logger.error("Unable to delete blob file for message " + m,e);
      }
    }
  }
  return mList;
}
 

Example 14

From project jboss-ejb3-tutorial, under directory /interceptor/src/org/jboss/tutorial/interceptor/bean/.

Source file: AccountsCancelInterceptor.java

  21 
vote

public Object sendCancelMessage(InvocationContext ctx) throws Exception {
  QueueSession session=null;
  try {
    System.out.println("*** AccountsCancelInterceptor intercepting " + ctx.getMethod().getName());
    System.out.println("*** AccountsConfirmInterceptor - notifying accounts dept");
    session=getConnection().createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
    Message msg=session.createTextMessage("Cancelling order " + ctx.getParameters()[0]);
    QueueSender sender=session.createSender(queue);
    sender.send(msg);
    return ctx.proceed();
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
 finally {
    try {
      session.close();
    }
 catch (    Exception e) {
    }
    System.out.println("*** AccountsCancelInterceptor exiting");
  }
}
 

Example 15

From project jentrata-msh, under directory /Plugins/CorvusEbMS/src/test/java/hk/hku/cecid/ebms/spa/client/jms/.

Source file: MessageListenerJMSClientTest.java

  21 
vote

/** 
 * Test of messageReceived method, of class JMSClient.
 * @throws SOAPException
 */
@Test public void testMessageReceived() throws SOAPException, JMSException {
  EbxmlMessage requestMessage=spy(new EbxmlMessage());
  String messageBody="This is a test message";
  SOAPMessage inMsg=mock(SOAPMessage.class);
  AttachmentPart inPart=mock(AttachmentPart.class);
  doReturn(new ByteArrayInputStream(messageBody.getBytes())).when(inPart).getRawContent();
  List<AttachmentPart> attachments=new ArrayList<AttachmentPart>();
  attachments.add(inPart);
  doReturn(attachments.iterator()).when(inMsg).getAttachments();
  inMsg.addAttachmentPart(inPart);
  doReturn(inMsg).when(requestMessage).getSOAPMessage();
  doReturn("cpaid2").when(requestMessage).getCpaId();
  doReturn("http://10.1.1.234:8080/corvus/httpd/ebms/inbound").when(requestMessage).getService();
  doReturn("B_Send_to_A").when(requestMessage).getAction();
  doReturn("convid").when(requestMessage).getConversationId();
  doReturn("serviceType").when(requestMessage).getServiceType();
  instance.messageReceived(requestMessage);
  consumer=session.createConsumer(queue);
  Message message=consumer.receive(100);
  assertNotNull(message);
  assertTrue(message instanceof TextMessage);
  TextMessage textMessage=(TextMessage)message;
  assertEquals(messageBody.length(),textMessage.getText().length());
  assertEquals(messageBody,textMessage.getText());
  assertEquals("cpaid2",textMessage.getStringProperty(MessageListenerJMSClient.MSG_PROPERTY_CPA_ID));
  assertEquals("http://10.1.1.234:8080/corvus/httpd/ebms/inbound",textMessage.getStringProperty(MessageListenerJMSClient.MSG_PROPERTY_SERVICE));
  assertEquals("B_Send_to_A",textMessage.getStringProperty(MessageListenerJMSClient.MSG_PROPERTY_ACTION));
  assertEquals("convid",textMessage.getStringProperty(MessageListenerJMSClient.MSG_PROPERTY_CONV_ID));
  assertEquals("serviceType",textMessage.getStringProperty(MessageListenerJMSClient.MSG_PROPERTY_SERVICE_TYPE));
}
 

Example 16

From project activemq-apollo, under directory /apollo-util/src/test/scala/org/apache/activemq/apollo/util/.

Source file: MessageIdList.java

  19 
vote

public void onMessage(Message message){
  String id=null;
  try {
    id=message.getJMSMessageID();
synchronized (semaphore) {
      messageIds.add(id);
      semaphore.notifyAll();
    }
    if (countDownLatch != null) {
      countDownLatch.countDown();
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("Received message: " + message);
    }
  }
 catch (  JMSException e) {
    e.printStackTrace();
  }
  if (parent != null) {
    parent.onMessage(message);
  }
  if (processingDelay > 0) {
    try {
      Thread.sleep(processingDelay);
    }
 catch (    InterruptedException e) {
    }
  }
}
 

Example 17

From project bam, under directory /modules/event-processor-network/epn-container-jee/src/main/java/org/overlord/bam/epn/jee/.

Source file: EPNEventsServer.java

  19 
vote

/** 
 * {@inheritDoc}
 */
public void onMessage(Message message){
  if (LOG.isLoggable(Level.FINEST)) {
    LOG.finest("Received events '" + message + "' - sending to "+ _epnManager);
  }
  if (_epnManager != null) {
    try {
      _epnManager.handleEventsMessage(message);
    }
 catch (    Exception e) {
      LOG.log(Level.SEVERE,java.util.PropertyResourceBundle.getBundle("epn-container-jee.Messages").getString("EPN-CONTAINER-JEE-5"),e);
    }
  }
}
 

Example 18

From project camelpe, under directory /examples/loan-broker-common/src/test/java/net/camelpe/examples/loanbroker/queue/.

Source file: LoanBrokerQueueInContainerTest.java

  19 
vote

@Test public void assertThatLoanBrokerProcessesLoanRequest() throws Exception {
  final String ssn="Client-A";
  final String loanRequest="Request quote for lowest rate of lending bank";
  final CountDownLatch loanReplyReceived=new CountDownLatch(1);
  final AtomicReference<Message> receivedLoanReply=new AtomicReference<Message>();
  final MessageListener loanReplyListenerDelegate=new MessageListener(){
    @Override public void onMessage(    final Message arg0){
      receivedLoanReply.set(arg0);
      loanReplyReceived.countDown();
    }
  }
;
  final LoanReplyListener loanReplyListener=new LoanReplyListener(jmsServer,loanReplyListenerDelegate);
  loanReplyListener.start();
  final LoanRequestSender loanRequestSender=new LoanRequestSender(jmsServer);
  loanRequestSender.start();
  loanRequestSender.requestLoan(ssn,loanRequest);
  loanRequestSender.stop();
  loanReplyReceived.await();
  loanReplyListener.stop();
}
 

Example 19

From project Carolina-Digital-Repository, under directory /persistence/src/main/java/edu/unc/lib/dl/services/.

Source file: OperationsMessageSender.java

  19 
vote

public void sendAddOperation(String userid,Collection<PID> destinations,Collection<PID> added,Collection<PID> reordered,String depositId){
  Document msg=new Document();
  Element contentEl=createAtomEntry(msg,userid,destinations.iterator().next(),"add");
  Element add=new Element("add",CDR_MESSAGE_NS);
  contentEl.addContent(add);
  add.addContent(new Element("depositId",CDR_MESSAGE_NS).setText(depositId));
  for (  PID destination : destinations) {
    add.addContent(new Element("parent",CDR_MESSAGE_NS).setText(destination.getPid()));
  }
  Element subjects=new Element("subjects",CDR_MESSAGE_NS);
  add.addContent(subjects);
  for (  PID sub : added) {
    subjects.addContent(new Element("pid",CDR_MESSAGE_NS).setText(sub.getPid()));
  }
  Element reorderedEl=new Element("reordered",CDR_MESSAGE_NS);
  add.addContent(reorderedEl);
  for (  PID re : reordered) {
    reorderedEl.addContent(new Element("pid",CDR_MESSAGE_NS).setText(re.getPid()));
  }
  XMLOutputter out=new XMLOutputter();
  final String msgStr=out.outputString(msg);
  this.jmsTemplate.send(new MessageCreator(){
    @Override public Message createMessage(    Session session) throws JMSException {
      return session.createTextMessage(msgStr);
    }
  }
);
  LOG.debug("sent add operation JMS message using JMS template:" + this.getJmsTemplate().toString());
}
 

Example 20

From project Cilia_1, under directory /components/jms-adapter/src/main/java/fr/liglab/adele/cilia/jms/.

Source file: JMSCollector.java

  19 
vote

public void onMessage(Message msg){
  Enumeration enume=null;
  try {
    enume=msg.getPropertyNames();
    Object content=null;
    Hashtable dico=new Hashtable();
    String name="jms-message";
    if (msg instanceof TextMessage) {
      content=((TextMessage)msg).getText();
    }
 else     if (msg instanceof ObjectMessage) {
      content=((ObjectMessage)msg).getObject();
    }
 else     if (msg instanceof MapMessage) {
      MapMessage message=(MapMessage)msg;
      enume=message.getMapNames();
      if (message.getObject(Data.DATA_CONTENT) != null) {
        content=message.getObject(Data.DATA_CONTENT);
      }
      if (message.getString(Data.DATA_NAME) != null) {
        name=message.getString(Data.DATA_NAME);
      }
      while (enume.hasMoreElements()) {
        String propname=(String)enume.nextElement();
        Object ob=((MapMessage)msg).getObject(propname);
        dico.put(propname,ob);
      }
    }
    Data ndata=new Data(content,name,dico);
    notifyDataArrival(ndata);
  }
 catch (  JMSException e) {
    e.printStackTrace();
  }
}
 

Example 21

From project collector, under directory /src/main/java/com/ning/metrics/collector/realtime/amq/.

Source file: ActiveMQSession.java

  19 
vote

protected Message createMessage(Object event) throws JMSException {
  final String eventStr=event.toString();
  if (useBytesMessage.get()) {
    BytesMessage msg=session.createBytesMessage();
    msg.writeBytes(eventStr.getBytes(UTF8));
    return msg;
  }
  return session.createTextMessage(eventStr);
}
 

Example 22

From project core_1, under directory /test/src/main/java/org/switchyard/test/mixins/.

Source file: HornetQMixIn.java

  19 
vote

/** 
 * Reads the body of a JMS  {@link Message} as a byte[].
 * @param msg JMS {@link Message}
 * @return the byte[] read.
 * @throws JMSException if an error occurs while trying to read the body content.
 */
public byte[] readBytesFromJMSMessage(final Message msg) throws JMSException {
  Assert.assertTrue(msg instanceof BytesMessage);
  BytesMessage bsMsg=(BytesMessage)msg;
  if (bsMsg.getBodyLength() >= Integer.MAX_VALUE) {
    Assert.fail("Message body is too large[" + bsMsg.getBodyLength() + "]: extract it manually.");
  }
  byte[] ba=new byte[(int)bsMsg.getBodyLength()];
  bsMsg.readBytes(ba);
  return ba;
}
 

Example 23

From project iudex_1, under directory /iudex-brutefuzzy-service/src/main/java/iudex/brutefuzzy/service/.

Source file: Client.java

  19 
vote

@Override public void onMessage(Message msg){
  try {
    if (msg instanceof BytesMessage) {
      BytesMessage bmsg=(BytesMessage)msg;
      byte[] body=new byte[(int)bmsg.getBodyLength()];
      bmsg.readBytes(body);
      if (_log.isDebugEnabled()) {
        onResponse(Response.parseFrom(body));
      }
    }
 else {
      _log.error("Received invalid message type: {}",msg.getClass().getName());
    }
  }
 catch (  JMSException x) {
    if (_log.isDebugEnabled())     _log.error("onMessage:",x);
 else     _log.error("onMessage: {}",x.toString());
  }
catch (  InvalidProtocolBufferException x) {
    if (_log.isDebugEnabled())     _log.error("onMessage:",x);
 else     _log.error("onMessage: {}",x.toString());
  }
}
 

Example 24

From project Ivory, under directory /messaging/src/main/java/org/apache/ivory/messaging/.

Source file: EntityInstanceMessageCreator.java

  19 
vote

public Message createMessage(Session session) throws JMSException {
  mapMessage=session.createMapMessage();
  for (  Entry<ARG,String> entry : instanceMessage.getKeyValueMap().entrySet()) {
    mapMessage.setString(entry.getKey().getArgName(),instanceMessage.getKeyValueMap().get(entry.getKey()));
  }
  return mapMessage;
}
 

Example 25

From project java-maven-tests, under directory /src/spring-jms-demo/src/main/java/com/alexshabanov/springjmsdemo/service/.

Source file: JmsMessageListener.java

  19 
vote

/** 
 * Implementation of <code>MessageListener</code>.
 */
public void onMessage(Message message){
  try {
    int messageCount=message.getIntProperty(JmsProducer.MESSAGE_COUNT);
    if (message instanceof TextMessage) {
      TextMessage tm=(TextMessage)message;
      String msg=tm.getText();
      logger.info("Processed message '{}'.  value={}",msg,messageCount);
      counter.incrementAndGet();
    }
  }
 catch (  JMSException e) {
    logger.error(e.getMessage(),e);
  }
}
 

Example 26

From project javaee-tutorial, under directory /jms/sar/src/main/java/org/jboss/ee/tutorial/jms/service/.

Source file: AuctionService.java

  19 
vote

@Override public void onMessage(Message message){
  log.infof("onMessage: %s",message);
  try {
    if (message instanceof BytesMessage) {
      String name=message.getStringProperty("auction.name");
      String bid=message.getStringProperty("auction.bid");
      Auction auction=auctions.get(name);
      auction.addBid(new Integer(bid));
    }
 else {
      log.warnf("Invalid message: %s",message);
    }
  }
 catch (  JMSException ex) {
    log.errorf(ex,"Cannot process message: %s",message);
  }
}
 

Example 27

From project jBilling, under directory /src/java/com/sapienter/jbilling/server/payment/event/.

Source file: ProcessPaymentMDB.java

  19 
vote

public void onMessage(Message message){
  try {
    LOG.debug("Processing message. Processor " + message.getStringProperty("processor") + " entity "+ message.getIntProperty("entityId")+ " by "+ this.hashCode());
    MapMessage myMessage=(MapMessage)message;
    IBillingProcessSessionBean process=(IBillingProcessSessionBean)Context.getBean(Context.Name.BILLING_PROCESS_SESSION);
    String type=message.getStringProperty("type");
    if (type.equals("payment")) {
      LOG.debug("Now processing asynch payment:" + " processId: " + myMessage.getInt("processId") + " runId:"+ myMessage.getInt("runId")+ " invoiceId:"+ myMessage.getInt("invoiceId"));
      Integer invoiceId=(myMessage.getInt("invoiceId") == -1) ? null : myMessage.getInt("invoiceId");
      if (invoiceId != null) {
        new InvoiceDAS().findForUpdate(invoiceId);
      }
      process.processPayment((myMessage.getInt("processId") == -1) ? null : myMessage.getInt("processId"),(myMessage.getInt("runId") == -1) ? null : myMessage.getInt("runId"),invoiceId);
      LOG.debug("Done");
    }
 else     if (type.equals("ender")) {
      process.endPayments(myMessage.getInt("runId"));
    }
 else {
      LOG.error("Can not process message of type " + type);
    }
  }
 catch (  Exception e) {
    LOG.error("Generating payment",e);
  }
}
 

Example 28

From project jboss-as-quickstart, under directory /cmt/src/main/java/org/jboss/as/quickstarts/cmt/mdb/.

Source file: HelloWorldMDB.java

  19 
vote

/** 
 * @see MessageListener#onMessage(Message)
 */
public void onMessage(Message rcvMessage){
  TextMessage msg=null;
  try {
    if (rcvMessage instanceof TextMessage) {
      msg=(TextMessage)rcvMessage;
      LOGGER.info("Received Message: " + msg.getText());
    }
 else {
      LOGGER.warning("Message of wrong type: " + rcvMessage.getClass().getName());
    }
  }
 catch (  JMSException e) {
    throw new RuntimeException(e);
  }
}
 

Example 29

From project jmeter-components, under directory /src/main/java/com/atlantbh/jmeter/plugins/jmstools/.

Source file: BinaryMessageConverter.java

  19 
vote

@Override public Object fromMessage(Message message) throws JMSException, MessageConversionException {
  Enumeration<String> names=message.getPropertyNames();
  messageProperties=new HashMap<String,String>();
  while (names.hasMoreElements()) {
    String name=names.nextElement();
    messageProperties.put(name,message.getStringProperty(name));
  }
  BytesMessage bm=(BytesMessage)message;
  byte[] transfer=new byte[(int)bm.getBodyLength()];
  bm.readBytes(transfer);
  return new String(transfer);
}