Header Ads Widget

Responsive Advertisement

JMS connection for send message to mq queue using thread pool




D:\Software\Softwares\MQ7.0.1.5_cdimage_trial\cdimage_trial

 

  1. Install MQSeries using Softwares\MQ7.0.1.3_cdimage_trial\cdimage_trial\Setup.exe.
  2. Click WebSphere MQ Installation button. You might receive an error that WebSphere Eclipse Platform Version 3.0.1 is not installed.
  3. Click on the “View Launchpad”. Click the Software Requirements button.
  4. Expand WebSphere Eclipse Platform Version 3.0.1 and click on Network PB.  Go to the folder < Softwares\MQ7.0.1.3_cdimage_trial> \cdimage_trial\Prereqs\IES  and click on setup.exe file will be already entered so click the Open PB. The installation will begin.
  5. Click OK PB for the language. Default is English.
  6. Click Next PB on the welcome screen for WebSphere Eclipse Platform.
  7. Select I accept the terms in the license agreement RB, click Next PB.
  8. Click Next PB for the destination Folder.
  9. Click the Install PB to begin the installation of WebSphere Eclipse platform.
  10. Click the Finish PB and now click Refresh button. WebSphere Eclipse Platform Version 3.0.1 is installed.
  11. Click WebSphere MQ Installation button.
  12. Click Launch WebSphere MQ  Installer button.
  13. Welcome window click Next PB.
  14. Select I accept the terms in the license agreement RB, click Next PB.
  15. Select Custom RB and click Next PB.
  16. Click Change PB, enter C:\MQSeries for folder name, click OK PB.
  17. Click Next PB.
  18. Click Next PB, when it indicates data-files folder, leave as C:\MQSeries.
  19. Click Next PB, when it indicates log files folder, C:\MQSeries\log.
  20. Select all 4 features (Server, Client, Java Messaging, and Development Toolkit) on Features window.
  21. Click Next PB.
  22. Click Install PB.
  23. Answer ‘Yes’ to license query about purchasing sufficient license units.
  24. Click the Finish PB when file copying completes.
  25. Click Next PB when Prepare WebSphere MQ Wizard window appears. WebSphere MQ begins setting itself up. Make sure the NO RB is selected for the question - Are any of the domain controllers in your network running Windows 2000 Server and then click NEXT PB.
  26. Click the Setup the Default Configuration link to start the Default Configuration Wizard.
  27. Click Next PB.
  28. Click Next PB.
  29. uncheck box Join the queue manager to the default cluster called, and click Next PB
  30. Click Finish PB, Default configuration begins. Ignore ‘default configuration is partly complete’ warning message. Click Close PB when done.
  31. Click Next PB in Prepare WebSphere MQ Wizard window.
  32. When Wizard is finished, uncheck Launch WebSphere MQ Getting Started Help and uncheck Launch Notepad to view the release notes and click Finish PB.
  33. Some users may receive the following error: MQSeries is not properly configured.  This error is caused because your NA\Login needs to be added to the mqm group. If you get this error, Click Cancel PB and follow steps 20-25.
  34. Click Start>Settings>Control Panel>Administrative Tools>Computer Management.
  35. Expand Local Users and Groups in left pane. Then Select Groups.
  36. In Right Pane, double click on mqm. This opens the properties window for the mqm group.
  37. Click Add PB, select na.uis.kcm.com from Look in: drop down list.
  38. In bottom pane enter your NA Domain login and click Check Names PB. Your name will appear underlined. Click OK PB. Now your NA Domain login appears as a user of the mqm group.
  39. Click Apply PB, then close out..
  40. Installation is complete.



1.1.      UnInstalling WebSphere MQ 7.0.1.7




  1. Go to control panel
  2. Select programs and features.
  3. Select IBM webservice MQ
  4. Uninstall
  5. If need to reboot do it
  6. Else if any warning is there just proceeded.
  7. Thanks

After than add
C:\MQSeries\java\lib and pest all jar file in build path

 

A system for sending messages to a message queue using IBM MQ, utilizing multiple threads to handle tasks concurrently. Here’s an overview of each part of the code:

Step-by-Step Explanation:

Step 1: Main Class (JmsMain)

This is the entry point of the application.

Ø  Purpose:

ü  Create an instance of JmsCallMethod.

ü  Measure the execution time of the threadCreation() method, which is responsible for sending messages concurrently using threads.

java

public class JmsMain {

  static JmsCallMethod jmsCall;

 

  public static void main(String[] args) throws InterruptedException, ExecutionException {

    long startTime = System.currentTimeMillis();

   

    jmsCall = new JmsCallMethod();

    jmsCall.threadCreation();  // Create threads and send messages

   

    long endTime = System.currentTimeMillis();

    long totalTime = endTime - startTime;

    System.out.println("Total execution time: " + totalTime + " ms");

  }

}

 

Step 2: JmsCallMethod Class

This class is responsible for handling the actual MQ operations, including sending messages and creating multiple threads for task execution.

Ø  Key methods:

ü  sendMessage(): Sends a message to a specified queue using the QueueInterfaceImpl implementation.

ü  threadCreation(): Creates multiple threads using an ExecutorService to execute MyThread instances (which send messages).

java

public class JmsCallMethod {

  QueueInterfaceImpl qmimpl = new QueueInterfaceImpl();

 

  // Sends a message to the queue

  void sendMessage() {

    String qname = "csanfmstatus";

    String qManager = "QM_IN_MANDALKC_1";

    final String text = "<Emp id=\"1\"><name>Kartik</name><age>30</age><role>Developer</role><gen>Male</gen></Emp>";

   

    try {

      qmimpl.sendMessage(qManager, qname, text);

    } catch (JMSException e) {

      e.printStackTrace();

    }

  }

 

  // Creates threads to send messages concurrently

  void threadCreation() throws InterruptedException, ExecutionException {

    ExecutorService executor = Executors.newFixedThreadPool(20);

   

    for (int i = 0; i < 20; i++) {

      executor.execute(new MyThread("TaskTwo" + i, i));  // Create and execute threads

    }

   

    executor.shutdown();

    executor.awaitTermination(1, TimeUnit.SECONDS);

    System.out.println("All tasks are finished!");

  }

}

 

Step 3: MyThread Class

This class implements Runnable and is responsible for sending messages when executed by the threads.

Ø  Key methods:

ü  run(): This is the core method executed by each thread, where it sends a message to the queue and logs the time taken for execution.

java

public class MyThread implements Runnable {

  JmsCallMethod jmsCall = new JmsCallMethod();

  private String myName;

  private int count;

 

  MyThread(String name, int newcount) {

    this.myName = name;

    this.count = newcount;

  }

 

  @Override

  public void run() {

    long startTime = System.currentTimeMillis();

   

    jmsCall.sendMessage();  // Sends message using JmsCallMethod

   

    long endTime = System.currentTimeMillis();

    long totalTime = endTime - startTime;

    System.out.println("Thread name = " + this.myName + " and execution time is = " + totalTime + " ms");

  }

}

 

Step 4: QueueInterface Interface

This is an interface that defines the contract for sending messages.

Ø  Key methods:

ü  sendMessage(): Defines the method signature for sending a message to the queue.

java

public interface QueueInterface {

  void sendMessage(String queueManagerName, String queueName, String sendTextMessage) throws JMSException;

}

 

Step 5: QueueInterfaceImpl Class

This is the implementation of the QueueInterface, which uses IBM MQ to send messages to the queue.

Ø  Key methods:

ü  initialize(): Sets up the connection factory and prepares the queue manager for message transmission.

ü  sendMessage(): Connects to the queue manager, creates a session, and sends the message to the specified queue.

java

public class QueueInterfaceImpl implements QueueInterface {

  public static MQQueueConnectionFactory connectionFactory = null;

  public static MQQueueConnection connection = null;

  public static MQQueueSession senderSession = null;

  public static MQQueueSender senderQueue = null;

 

  // Initializes the connection to the queue manager

  public void initialize(String queueManager) {

    try {

      connectionFactory = new MQQueueConnectionFactory();

      connectionFactory.setHostName("localhost");

      connectionFactory.setPort(1414);

      connectionFactory.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_BINDINGS);

      connectionFactory.setQueueManager(queueManager);

      connectionFactory.setChannel("SYSTEM.ADMIN.SVRCONN");

    } catch (JMSException e) {

      e.printStackTrace();

    }

  }

 

  @Override

  public void sendMessage(String queueManagerName, String queueName, String sendTextMessage) throws JMSException {

    initialize(queueManagerName);

   

    connection = (MQQueueConnection) connectionFactory.createQueueConnection();

    senderSession = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    com.ibm.mq.jms.MQQueue queue = (com.ibm.mq.jms.MQQueue) senderSession.createQueue(queueName);

    senderQueue = (MQQueueSender) senderSession.createSender(queue);

   

    long uniqueNumber = System.currentTimeMillis() % 1000;

    TextMessage message = senderSession.createTextMessage(sendTextMessage + uniqueNumber);

   

    connection.start();

    senderQueue.send(message);

    System.out.println("Sent message: " + message.getText());

   

    senderQueue.close();

    senderSession.close();

    connection.close();

  }

}

 

Summary:

Ø  Multithreading: The JmsCallMethod class creates multiple threads using ExecutorService, and each thread sends a message to an IBM MQ queue.

Ø  Message Sending: The QueueInterfaceImpl class manages the connection to IBM MQ and sends the actual message.

Ø  Message Construction: The messages being sent are in XML format, representing an employee entity.

This architecture can be scaled by adjusting the number of threads and is suitable for high-throughput messaging systems.

 


one message is delivered to one receiver only. Here, Queue is used as a Message Oriented Middleware (MOM)
In PTP model
one message is delivered to all the subscribers. It is like broadcasting. Here, Topic is used as a message oriented middleware that is responsible to hold and deliver messages.
In Pub/Sub model

Message Driven Bean (MDB)
JMS Programming Model







Post a Comment

0 Comments