Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 1 | /* |
Gaurav Gupta | 3655507 | 2020-03-26 14:10:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 3 | * |
| 4 | * This program and the accompanying materials are made available under the |
| 5 | * terms of the Eclipse Public License v. 2.0, which is available at |
| 6 | * http://www.eclipse.org/legal/epl-2.0. |
| 7 | * |
| 8 | * This Source Code may also be made available under the following Secondary |
| 9 | * Licenses when the conditions for such availability set forth in the |
| 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| 11 | * version 2 with the GNU Classpath Exception, which is available at |
| 12 | * https://www.gnu.org/software/classpath/license.html. |
| 13 | * |
| 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| 15 | */ |
| 16 | |
| 17 | package org.glassfish.test.jms.mdbdest.ejb; |
| 18 | |
| 19 | import java.util.logging.*; |
Lukas Jungmann | df23908 | 2020-04-29 13:37:31 +0200 | [diff] [blame] | 20 | import jakarta.annotation.Resource; |
Gaurav Gupta | ed5e731 | 2020-05-01 07:54:26 +0530 | [diff] [blame] | 21 | import jakarta.ejb.*; |
Gaurav Gupta | 508d875 | 2020-05-04 11:01:28 +0530 | [diff] [blame] | 22 | import jakarta.inject.Inject; |
Gaurav Gupta | 3655507 | 2020-03-26 14:10:23 +0530 | [diff] [blame] | 23 | import jakarta.jms.*; |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 24 | |
| 25 | @MessageDriven(name = "test0", mappedName = "jms/jms_unit_test_Topic", activationConfig = { |
| 26 | @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), |
Gaurav Gupta | 3655507 | 2020-03-26 14:10:23 +0530 | [diff] [blame] | 27 | @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"), |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 28 | @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "java:comp/DefaultJMSConnectionFactory") |
| 29 | }) |
| 30 | public class NewMessageBean implements MessageListener { |
| 31 | private static final Logger logger = Logger.getLogger(NewMessageBean.class.getName()); |
David Matějček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 32 | |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 33 | private static int count; |
David Matějček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 34 | |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 35 | @Resource |
| 36 | private MessageDrivenContext mdc; |
| 37 | |
| 38 | @Resource(mappedName = "jms/jms_unit_result_Queue") |
| 39 | private Queue resultQueue; |
| 40 | |
| 41 | @Inject |
| 42 | @JMSConnectionFactory("jms/jms_unit_test_QCF") |
| 43 | @JMSSessionMode(JMSContext.AUTO_ACKNOWLEDGE) |
| 44 | private JMSContext jmsContext; |
David Matějček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 45 | |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 46 | public NewMessageBean() { |
| 47 | } |
David Matějček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 48 | |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 49 | @Override |
| 50 | @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) |
| 51 | public void onMessage(Message message) { |
| 52 | JMSProducer producer = jmsContext.createProducer(); |
| 53 | TextMessage tmsg = jmsContext.createTextMessage("Received: " + this.getClass().getName()); |
| 54 | producer.send(resultQueue, tmsg); |
| 55 | System.out.println(this.getClass().getName() + " sent message!!!"); |
| 56 | } |
| 57 | } |