Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using System MessageQueues with Unity

Discussion in 'Scripting' started by BooNonMooN, Aug 3, 2017.

  1. BooNonMooN

    BooNonMooN

    Joined:
    May 20, 2013
    Posts:
    10
    HI all.

    I am currently trying to implement message queus for ipc communication from unity to an external process.
    Creating the queue seems to work, at least I do not get any exceptions, but I am unable to send or read to/from the MQ.

    included dlls in Plugins:
    Mono.Messaging
    Mono.Messaging.RabbitMQ
    RabbitMQ.Client
    System.Messaging

    Queue creation:

    Code (CSharp):
    1.  private void CreateQueue()
    2.     {
    3.         try
    4.         {
    5.             if (MessageQueue.Exists(MSQ_PATH))
    6.             {
    7.                 print("Queue already there, connecting to it");
    8.                 msgMessageQueue = new MessageQueue(MSQ_PATH);
    9.                 //  msgMessageQueue.Label = MSQ_DESC;
    10.  
    11.             }
    12.             //Queue needs to be created
    13.             else
    14.             {
    15.                 print("Queue not found, crating new Queue");
    16.                 msgMessageQueue = MessageQueue.Create(MSQ_PATH);
    17.                 // msgMessageQueue.Label = MSQ_DESC;
    18.             }
    19.         }
    20.         catch (Exception ex)
    21.         {
    22.             Debug.LogError("Error during Queue creation: " + ex.Message);
    23.         }
    24.     }

    Sending MSG


    Code (CSharp):
    1. public void SendMessageToQueue(string msg)
    2.     {
    3.         try
    4.         {
    5.             Message recoverableMessage = new Message(msg);
    6.            // recoverableMessage.Body = msg;
    7.            // recoverableMessage.Recoverable = true;
    8.             MessageQueue msgQ = new MessageQueue(MSQ_PATH);
    9.             msgQ.Formatter = new BinaryMessageFormatter();
    10.             msgQ.Send(recoverableMessage);
    11.  
    12.         }
    13.         catch (Exception ex)
    14.         {
    15.             Debug.LogError("Error sending message to Queue: " + ex.Message);
    16.         }
    17.     }
    Error: Error sending message to Queue: Unable to connect to Queue

    Thanks in advance.