MSMQ message sending & receiving & pit avoidance

MSMQ create queue (local):

  private queue - New - Private queue - queue name: MessageQueuing - check transactional

  environment configuration:

  first, you need to download the configuration file: https://download.csdn.net/download/qq_24950043/11662752

  CSDN article: https://blog.csdn.net/qq_24950043/article/details/100529486

  commissioning results:

  1. The article says that the first three files need to be placed in the bin directory of jre, but I found that I don't need them after repeated tests

  2. The first file needs to be placed under C:\Windows\System32. I am a 64 bit system, which is different from what is said in the article

  3. You need to build a lib under the project to import the fourth jar file. This is OK

  4. Queue permissions. After my test, I don't need to configure whether it's local or remote

  sending code:

package com.queuing;
import ionic.Msmq.Message;
import ionic.Msmq.MessageQueueException;
import ionic.Msmq.Queue;

public class TestMessage {
    //192.168.125.116 is the local IP address (127.0.0.1 cannot be used after testing, otherwise an error will be reported). private$\MessageQueuing is the queue name
    static String fullname="direct=tcp:192.168.125.116\\private$\\MessageQueuing";

    public static void main(String[] args) {
        send();
    }

    /**
     * send out
     */
    public static void send() {
        try {
            // Parameter 1: queue address; Parameter 2: queue type 1 receive, 2 send; Parameter 3: transactional
            Queue queue= new Queue(fullname,2,true);
            //title
            String label="testmessage";
            //content
            String body= "45634";
            //A property of the message header that identifies a particular message by association
            String correlationId = "12334";
            //Create message
            // Parameter 1: label; Parameter 2: id; Parameter 3: send content
            Message msg= new Message(body, label, correlationId);
            //send out
            queue.send(msg);
            //close
            queue.close();
            System.out.println("Sent successfully");
        } catch (Exception e) {
            System.out.println("fail in send");
        }
    }
}



  consumption Code:

package com.queuing;
import ionic.Msmq.Message;
import ionic.Msmq.MessageQueueException;
import ionic.Msmq.Queue;

public class TestMessage {
    //192.168.125.116 is the local IP address (127.0.0.1 cannot be used after testing, otherwise an error will be reported). private$\MessageQueuing is the queue name
    static String fullname="direct=tcp:192.168.125.116\\private$\\MessageQueuing";

    public static void main(String[] args) {
        receive();
    }
        /**
     * receive
     * @throws Exception
     */
    public static void receive(){
        try {
            Queue receiveQueue = new Queue(fullname,1,true);
            //Queue receiveQueue = new Queue(fullname);  You can also get the queue in this way
            // Delete this message after receiving
            Message message = receiveQueue.receive();
            //Message message = receiveQueue.peek();  Do not delete this message after receiving
            System.out.println("Receive content");
            // Get label
            System.out.println(message.getLabel());
            // Get ID
            System.out.println(message.getCorrelationId());
            // Get content
            System.out.println(message.getMessage());
            //close
            receiveQueue.close();
        }
        catch (MessageQueueException ex1) {
            System.out.println("Queue is empty");
            ex1.printStackTrace();
        } catch (Exception e) {
            System.out.println("Queue error");
            e.printStackTrace();
        }
    }
}



   if the above is normal, then abnormal conditions:

  modify the sent ip. I wrote this ip casually

//192.168.125.116 is the local IP address (127.0.0.1 cannot be used after testing, otherwise an error will be reported). private$\MessageQueuing is the queue name
static String fullname="direct=tcp:192.168.125.999\\private$\\MessageQueuing";

    at this time, records appear in the outgoing queue. One message is not sent. The status is waiting for connection, because the ip does not exist

  here is an example. If there is a problem, you can view and analyze it here

  the problems encountered at present are as follows:

1. Waiting for connection
2. Inactive connection to Winsock socket failed. Address: IP =
3. Waiting for connection. TCP is not installed or enabled

MSMQ create queue (remote):


  now another computer sends messages. The sending ip in the code is changed to 119. The queue name is Message

static String fullname="direct=tcp:192.168.125.119\\private$\\Message";

  view the outgoing queue record information of MSMQ on the computer sending the message: the status is connected and the connection can be delivered

  now check the Message queue received by the remote MSMQ. The Message has been received

  now I'm testing remote consumption, but the result directly reports an error. I found an article

  article link: https://blog.csdn.net/weixin_41969980/article/details/86649983

  configuration content:

  1. Right click message queue - properties - server security - uncheck all options

  2. Queue permissions, all three configured



  3. registry

  under security, add AllowNonauthenticatedRpc and newremotereaderserverdenyworkgroupclient, both of which are 1

  after the configuration is completed, the consumption test again, and the result is still an error.

   the current situation is that you can send and receive locally, and the remote end can only send, and the necessary condition for remote sending is that the local machine must also have MSMQ, that is, you must interact on the Win system. Linux can't do this.

Added by Dimensional on Mon, 17 Jan 2022 00:02:57 +0200