Advertisement
Guest User

Untitled

a guest
Jun 5th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. @MessageDriven(name = "SubscribersTopicQueueMDB", activationConfig = {
  2. @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/topic/Subscribers"),
  3. @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
  4. @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
  5. public class SubscribersTopicQueueMDB implements MessageListener {
  6.  
  7. private final static Logger LOGGER = Logger.getLogger(SubscribersTopicQueueMDB.class.toString());
  8.  
  9. public SubscribersTopicQueueMDB() {
  10. System.out.println("Topic: SubscribersTopicQueueMDB INIT ");
  11. }
  12.  
  13. and
  14. @MessageDriven(name = "SubscribersTopicSecondMDB", activationConfig = {
  15. @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/topic/Subscriber"),
  16. @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
  17. @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
  18. public class SubscribersTopicSecondMDB implements MessageListener {
  19.  
  20. private final static Logger LOGGER = Logger.getLogger(SubscribersTopicSecondMDB.class.toString());
  21.  
  22. public SubscribersTopicSecondMDB() {
  23. System.out.println("TOPIC: SubscribersTopicSecondMDB (Second) INIT ");
  24. }
  25.  
  26. public static void sendTextMessage(String message, String passedDestination) {
  27. if (message == null || passedDestination == null) {
  28. return;
  29. }
  30. Context namingContext = null;
  31.  
  32. try {
  33. String userName = JMS_DEFAULT_USERNAME;
  34. String password = JMS_DEFAULT_PASSWORD;
  35. // Set up the namingContext for the JNDI lookup
  36. final Properties env = new Properties();
  37. env.put(Context.INITIAL_CONTEXT_FACTORY, JMS_INITIAL_CONTEXT_FACTORY);
  38. env.put(Context.PROVIDER_URL, JMS_PROVIDER_URL);
  39. // env.put(Context.SECURITY_PRINCIPAL, userName);
  40. // env.put(Context.SECURITY_CREDENTIALS, password);
  41. namingContext = new InitialContext(env);
  42. // Perform the JNDI lookups
  43. String connectionFactoryString = JMS_DEFAULT_CONNECTION_FACTORY;
  44. System.out.println("+@@Attempting to acquire connection factory "" + connectionFactoryString + """);
  45. ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);
  46. System.out.println("+@@@Found connection factory "" + connectionFactoryString + "" in JNDI " + connectionFactory.toString());
  47.  
  48. String destinationString = passedDestination;
  49. System.out.println("+@@Attempting to acquire destination "" + destinationString + """);
  50. Destination destination = (Destination) namingContext.lookup(destinationString);
  51. System.out.println("+@@@Found destination "" + destinationString + "" in JNDI");
  52.  
  53. int count = 2;
  54. String content = message;
  55. //System.out.println("userName " + userName);
  56. //System.out.println("password " + password);
  57. try (JMSContext context = connectionFactory.createContext()) {
  58. System.out.println("***************Sending to " + destinationString + " messages with content: " + content + " *********************");
  59. context.createProducer().send(destination, content);
  60.  
  61. }
  62. //return true;
  63. } catch (NamingException e) {
  64. e.printStackTrace();
  65. } finally {
  66. if (namingContext != null) {
  67. try {
  68. namingContext.close();
  69. } catch (NamingException e) {
  70. e.printStackTrace();
  71. }
  72. }
  73. // return false;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement