Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @MessageDriven(name = "SubscribersTopicQueueMDB", activationConfig = {
- @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/topic/Subscribers"),
- @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
- @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
- public class SubscribersTopicQueueMDB implements MessageListener {
- private final static Logger LOGGER = Logger.getLogger(SubscribersTopicQueueMDB.class.toString());
- public SubscribersTopicQueueMDB() {
- System.out.println("Topic: SubscribersTopicQueueMDB INIT ");
- }
- and
- @MessageDriven(name = "SubscribersTopicSecondMDB", activationConfig = {
- @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/topic/Subscriber"),
- @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
- @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
- public class SubscribersTopicSecondMDB implements MessageListener {
- private final static Logger LOGGER = Logger.getLogger(SubscribersTopicSecondMDB.class.toString());
- public SubscribersTopicSecondMDB() {
- System.out.println("TOPIC: SubscribersTopicSecondMDB (Second) INIT ");
- }
- public static void sendTextMessage(String message, String passedDestination) {
- if (message == null || passedDestination == null) {
- return;
- }
- Context namingContext = null;
- try {
- String userName = JMS_DEFAULT_USERNAME;
- String password = JMS_DEFAULT_PASSWORD;
- // Set up the namingContext for the JNDI lookup
- final Properties env = new Properties();
- env.put(Context.INITIAL_CONTEXT_FACTORY, JMS_INITIAL_CONTEXT_FACTORY);
- env.put(Context.PROVIDER_URL, JMS_PROVIDER_URL);
- // env.put(Context.SECURITY_PRINCIPAL, userName);
- // env.put(Context.SECURITY_CREDENTIALS, password);
- namingContext = new InitialContext(env);
- // Perform the JNDI lookups
- String connectionFactoryString = JMS_DEFAULT_CONNECTION_FACTORY;
- System.out.println("+@@Attempting to acquire connection factory "" + connectionFactoryString + """);
- ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);
- System.out.println("+@@@Found connection factory "" + connectionFactoryString + "" in JNDI " + connectionFactory.toString());
- String destinationString = passedDestination;
- System.out.println("+@@Attempting to acquire destination "" + destinationString + """);
- Destination destination = (Destination) namingContext.lookup(destinationString);
- System.out.println("+@@@Found destination "" + destinationString + "" in JNDI");
- int count = 2;
- String content = message;
- //System.out.println("userName " + userName);
- //System.out.println("password " + password);
- try (JMSContext context = connectionFactory.createContext()) {
- System.out.println("***************Sending to " + destinationString + " messages with content: " + content + " *********************");
- context.createProducer().send(destination, content);
- }
- //return true;
- } catch (NamingException e) {
- e.printStackTrace();
- } finally {
- if (namingContext != null) {
- try {
- namingContext.close();
- } catch (NamingException e) {
- e.printStackTrace();
- }
- }
- // return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement