blob: 33098599d441c766ed4824698c4f47e06970256a [file] [log] [blame]
Vinay Vishal57171472018-09-18 20:22:00 +05301/*
Gaurav Gupta36555072020-03-26 14:10:23 +05302 * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved.
Vinay Vishal57171472018-09-18 20:22:00 +05303 *
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
17package org.glassfish.test.jms.mdbdest.ejb;
18
19import java.util.logging.*;
Lukas Jungmanndf239082020-04-29 13:37:31 +020020import jakarta.annotation.Resource;
Gaurav Guptaed5e7312020-05-01 07:54:26 +053021import jakarta.ejb.*;
Gaurav Gupta508d8752020-05-04 11:01:28 +053022import jakarta.inject.Inject;
Gaurav Gupta36555072020-03-26 14:10:23 +053023import jakarta.jms.*;
Vinay Vishal57171472018-09-18 20:22:00 +053024
25@MessageDriven(name = "test0", mappedName = "jms/jms_unit_test_Topic", activationConfig = {
26 @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
Gaurav Gupta36555072020-03-26 14:10:23 +053027 @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"),
Vinay Vishal57171472018-09-18 20:22:00 +053028 @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "java:comp/DefaultJMSConnectionFactory")
29})
30public class NewMessageBean implements MessageListener {
31 private static final Logger logger = Logger.getLogger(NewMessageBean.class.getName());
David Matějčekf4dc06a2021-05-17 12:10:57 +020032
Vinay Vishal57171472018-09-18 20:22:00 +053033 private static int count;
David Matějčekf4dc06a2021-05-17 12:10:57 +020034
Vinay Vishal57171472018-09-18 20:22:00 +053035 @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čekf4dc06a2021-05-17 12:10:57 +020045
Vinay Vishal57171472018-09-18 20:22:00 +053046 public NewMessageBean() {
47 }
David Matějčekf4dc06a2021-05-17 12:10:57 +020048
Vinay Vishal57171472018-09-18 20:22:00 +053049 @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}