Пример #1
0
 /**
  * <summary>
  * Retrieves the message identified by <c>id</c> in the message's
  * recipt id, set prior to the message having been enqueued (See:
  * <c>Enqueue(QueueMessage)</c>. The results  are placed in the object
  * <c>msg</c>.
  * </summary>
  *
  * <remarks>
  * <para>Note: Message responsders will typically place the message id of the original
  * message in the recipt id of the message being returned.  This round-trip
  * message identification is provided by SAFMQ as a method for coordinated two-way
  * communications.</para>
  *
  * <para>Note: Retrieved messages are removed from the queue.</para>
  * </remarks>
  *
  * <param name="retrievebody">
  *                      A flag indicating whether the body of the message should be retrieved</param>
  * <param name="id">    The UUID of the message to be retrieved.</param>
  * <param name="timeout">
  *                      The number of seconds to wait before returning, a value of zero (0) will
  *                      cause the method to return immediately if no messages are present on the queue,
  *                      a value of (-1) will cause the method to wait until a message is placed on the queue.
  *                      </param>
  * <param name="msg">   Receives the contents of the message.</param>
  *
  * <returns>Upon success a value of <c>Safmq.EC_NOERROR</c>, otherwise
  *          see MQConnection.RetrieveID() for result codes.</returns>
  *
  * <seealso cref="MQConnection.RetrieveID(QueueHandle,bool,UUID,int,QueueMessage)">MQConnection.Retrieve(QueueHandle,bool,int,QueueMessage)</seealso>
  * <seealso cref="Enqueue(QueueMessage)">Enqueue(QueueMessage)</seealso>
  */
 public ErrorCode RetrieveID(bool retrievebody, UUID id, int timeout, QueueMessage msg)
 {
     return(con.RetrieveID(que, retrievebody, id, timeout, msg));
 }
Пример #2
0
        public void test_PeekID_PeekFront_OpenCursor_PeekCursor_SeekID_RetrieveCursor_AdvanceCursor_TestCurosr_CloseCursor_RetrieveID()
        {
            MQConnection con = null;

            try {
                con = connectToServer(address, null, null);

                addAllGroups(con);
                addAllUsers(con);
                addAllQueues(con);

                QueueHandle handle = new QueueHandle();
                ErrorCode   ec     = con.OpenQueue(TEST_QUEUE[0], handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to open queue: " + TEST_QUEUE[0]);

                sendMessages(con, handle, 5, 0);
                QueueMessage msg = new QueueMessage();
                StreamWriter sw  = new StreamWriter(msg.Stream);
                sw.WriteLine(SPECIAL_MESSAGE);
                sw.Close();

                byte[] b    = { 0, 0, 0, 0, 0, 0, 0, 0 };
                UUID   uuid = new UUID(new Guid(123456789, 4321, 1234, b));
                msg.ReciptID = uuid;
                //msg.ReciptID = ((UUID)uuid.Clone());

                ec = con.Enqueue(handle, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to write special message");

                sendMessages(con, handle, 5, 5);

                msg = new QueueMessage();
                ec  = con.PeekID(handle, true, uuid, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekID:" + ec);

                string txt = (new StreamReader(msg.Stream)).ReadLine();
                Console.WriteLine("txt:\t\t\t" + txt);
                Console.WriteLine("uuid:\t\t\t" + (Guid)uuid);
                Console.WriteLine("msg.ReceiptID:\t" + (Guid)msg.ReciptID);
                Console.WriteLine("txt.Equals(SPECIAL_MESSAGE): " + txt.Equals(SPECIAL_MESSAGE));
                Console.WriteLine("uuid.Equals(msg.ReceiptID)): " + uuid.Equals(msg.ReciptID));
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE) && uuid.Equals(msg.ReciptID), "Incorrect PeekID Message: " + (Guid)msg.ReciptID);

                msg = new QueueMessage();
                ec  = con.PeekFront(handle, true, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekFront");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("0"), "Incorrect PeekFront Message: body=" + txt);

                CursorHandle cur = new CursorHandle();

                ec = con.OpenCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to OpenCursor");

                ec = con.SeekID(handle, uuid, 0, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to SeekID");
                msg = new QueueMessage();
                ec  = con.PeekCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekCursor");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE) && uuid.Equals(msg.ReciptID), "Incorrect PeekCursor Message: " + msg.ReciptID);

                ec = con.AdvanceCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to AdvanceCursor");
                msg = new QueueMessage();
                ec  = con.PeekCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekCursor (after advance)");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("5"), "Incorrect PeekCursor (after advance) Message: " + msg.ReciptID);

                msg = new QueueMessage();
                ec  = con.RetrieveCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("5"), "Incorrect PeekCursor (after RetrieveCursor) Message: " + msg.ReciptID);

                ec = con.TestCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to test Cursor, ec: " + ec);

                ec = con.CloseCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to CloseCursor, ec: " + ec);


                msg = new QueueMessage();
                ec  = con.RetrieveID(handle, true, uuid, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveID");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE) && uuid.Equals(msg.ReciptID), "Incorrect RetrieveID Message: " + msg.ReciptID);

                int[] bodies = { 0, 1, 2, 3, 4, 6, 7, 8, 9 }; // 5 was retrieved above.
                for (int x = 0; x < bodies.Length; x++)
                {
                    msg = new QueueMessage();
                    ec  = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to retrieve message: " + x);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Console.WriteLine("txt: " + txt);
                    Assert.IsTrue(int.Parse(txt) == bodies[x], "Incorrect message: " + txt);
                }


                ec = con.CloseQueue(handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to Close queue");
            } finally {
                if (con != null)
                {
                    con.Close();
                }
            }
        }