public void test_CreateTempQueue() { using (MQConnection con = connectToServer(address, null, null)) { String queueName = String.Empty; QueueHandle qh = new QueueHandle(); // Try and create a temporary queue ErrorCode err = con.CreateTempQueue(out queueName, qh); Console.WriteLine("queueName:" + queueName); Assert.AreEqual(ErrorCode.EC_NOERROR, err, "Creating Queue"); // Get permissions for that queue List<QueuePermissions> perms = new List<QueuePermissions>(); con.QueueEnumeratePermissions(queueName, perms); for (int x = 0; x < perms.Count; ++x) { QueuePermissions perm = perms[x]; Console.WriteLine(perm.EntityName + ":" + perm.Read + ":" + perm.Write + ":" + perm.Destroy + ":" + perm.ChangeSecurity); } Assert.IsTrue(perms.Count > 0); addAllUsers(con); // Try and write to that queue with another user. using (MQConnection con2 = connectToServer(simpleAddress, TEST_USERS[0], TEST_USERS[0])) { QueueHandle qh2 = new QueueHandle(); ErrorCode rc = con2.OpenQueue(queueName, qh2); Assert.IsTrue(rc == ErrorCode.EC_NOERROR, "Open Temp Queue rc:" + rc); QueueMessage msg = new QueueMessage(); msg.Label = "Hello World"; Assert.IsTrue(ErrorCode.EC_NOERROR == con2.Enqueue(qh2, msg), "Enqueue to temp"); con2.CloseQueue(qh2); } } }
public void test_OpenQueue_Enqueue_Retrieve_CloseQueue() { 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); for(int x=0;x<5;x++) { QueueMessage msg = new QueueMessage(); ec = con.Retrieve(handle, true, 0, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to retrieve message: " + x); StreamReader r = new StreamReader(msg.Stream); string s = r.ReadLine(); Assert.IsTrue(int.Parse(s) == x, "Incorrect message retrieved: " + x); } ec = con.CloseQueue(handle); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to Close queue"); } finally { if (con != null) con.Close(); } }
public void test_EnqueueWithRelay() { MQConnection con = null; try { con = connectToServer(address, null, null); QueueMessage msg = new QueueMessage(); StreamWriter sw = new StreamWriter(msg.Stream); sw.WriteLine(SPECIAL_MESSAGE); sw.Close(); addAllQueues(con); ErrorCode ec = con.EnqueueWithRelay(new Uri(addressString + "/" + TEST_QUEUE[1]), msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to EnqueueWithRelay:" + ec); Thread.Sleep(100); QueueHandle handle = new QueueHandle(); ec = con.OpenQueue(TEST_QUEUE[1], handle); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to OpenQueue:" + ec); msg = new QueueMessage(); ec = con.Retrieve(handle, true, 0, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to Retrieve:" + ec); string txt = (new StreamReader(msg.Stream)).ReadLine(); Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE), "Incorrect Message: " + txt); ec = con.CloseQueue(handle); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to CloseQueue:" + ec); } finally { if (con != null) con.Close(); } }
/** * <summary> * Enqueues a message for message relay forwarding to another queue/queue server. * </summary> * * <remarks> * After completion, the return code will be EC_NOERROR on success and the <c>msg</c>'s * timestamp and message will have been set. It is important to note if the resposne * queue name is not set, any errors from the final destination queue/queue server will * be lost. It is suggested to use roundtripping unless error determination is not * required, otherwise errors generated by the final destination server such as:<br/> * <table border="0"> * <tr><td>EC_DOESNOTEXIST</td></tr> * <tr><td>EC_NOTAUTHORIZED</td></tr> * <tr><td>EC_WRONGMESSAGETYPE</td></tr> * <tr><td>EC_NOTOPEN</td></tr> * <tr><td>EC_FORWARDNOTALLOWED</td></tr> * <tr><td>EC_DUPLICATEMSGID</td></tr> * </table> * will not returned to the client. * </remarks> * * <param name="uri"> A safmq Uri in the format safmq://user:password@server:port/queuename -or- for ssl safmqs://user:password@server:port/queuename.<br/> * Note: the port specification is optional.</param> * <param name="msg"> The message to be sent.</param> * * <returns>ErrorCode.EC_NOERROR on success<br/> * <table border="0"> * <tr><td>ErrorCode.EC_INVALIDNAME</td><td>incase of an invalid url</td></tr> * <tr><td>ErrorCode.EC_NETWORKERROR</td></tr> * <tr><td>ErrorCode.EC_NOTAUTHORIZED</td></tr> * <tr><td>ErrorCode.EC_NOTOPEN</td></tr> * <tr><td>ErrorCode.EC_WRONGMESSAGETYPE</td></tr> * <tr><td>ErrorCode.EC_FORWARDNOTALLOWED</td></tr> * </table> * </returns> */ public ErrorCode EnqueueWithRelay(Uri uri, QueueMessage msg) { ErrorCode ret; try { QueueHandle forward = new QueueHandle(); string dest = ""; string userinfo = uri.UserInfo; string user, password; user = password = ""; ret = OpenQueue(FORWARD_QUEUE_NAME, forward); if (ret == ErrorCode.EC_NOERROR) { StringBuilder u, p; if (MQBuilder.parseUserInfo(userinfo, u = new StringBuilder(), p = new StringBuilder())) { user = u.ToString(); password = p.ToString(); } if (uri.Scheme.Length > 0) dest = uri.Scheme + ":"; dest += "//"; if (user.Length > 0) { dest += user; if (password.Length > 0) dest += ":" + password; dest += "@"; } dest += uri.Host; if (uri.Port > 0) dest += ":" + uri.Port; dest += uri.AbsolutePath; msg.Label = (dest + "?label=" + msg.Label); ret = Enqueue(forward, msg); ErrorCode ec = CloseQueue(forward); if (ret == ErrorCode.EC_NOERROR && ec != ErrorCode.EC_NOERROR) ret = ec; } else if (ret == ErrorCode.EC_DOESNOTEXIST) { ret = ErrorCode.EC_FORWARDNOTALLOWED; } } catch (Exception) { ret = ErrorCode.EC_INVALIDNAME; } return ret; }
/** * <summary> * Places a message on the queue. The object <c>msg</c> must have * been previously prepared before calling this method. Upon successfull sending * of the message, the message id and message timestamp will be set by the server * and may be retrieved by a call to <c>QueueMessage.getMessageID()</c> * and <c>QueueMessage.getTimeStamp()</c> respectively. * </summary> * <remarks> * <para>Note: Message responsders will typically place the message id of the original * message input 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> * </remarks> * * <param name="handle"> A reference to a queue opened by a call to <c>OpenQueue()</c> </param> * <param name="msg"> The message to be placed on the queue</param> * * <returns><c>ErrorCode.EC_NOERROR</c> on success, Otherwise results may be such listed * below but are not limited to: * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_ALREADYCLOSED</c></td> * <td>The queue reference is not valid as it has * been closed. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td> * <td>The user is not authorized to Write messages to this * queue. * </td></tr> * </table> * </returns> * * <seealso cref="OpenQueue(string, QueueHandle)"/> */ public ErrorCode Enqueue(QueueHandle handle, QueueMessage msg) { ErrorCode ret = ErrorCode.EC_NETWORKERROR; ENQUEUE_PARAMS parms = new ENQUEUE_PARAMS(); parms.queueID = handle; parms.msg = msg; try { output.Write(Safmq.CMD_ENQUEUE); parms.Write(output); output.Flush(); ret = getResponseCode(); if (ret == ErrorCode.EC_NOERROR) { ENQUEUE_RESPONSE_DATA data = new ENQUEUE_RESPONSE_DATA(); data.msgID = msg.MessageID; // set the response data msgID to the msg.messageID so that it can be Read back data.Read(input); msg.TimeStamp = data.timestamp; } } catch (Exception) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }
/** * <summary> * Creates a new temporary message queue. The queue is removed from the server * once all clients close their handles to the queue, explicitly or implicity * by disconnecting from the server.</summary> * * <remarks> * After calling <c>CreateTempQueue</c> the SAFMQ server has created a queue, * flagged as temporary, returns the server generated name of the queue, and a handle * to that queue. Closing the queue removes it from the system, there is no need to * explicitly delete it. Using the Closing technique, it is possible that the queue * may remain open, because other clients have access to the queue. * </remarks> * * <param name="tmpQueueName"> [out] Receives the name of the temporary queue, relative to the server, * when supplying this queue name to other clients, the server URL * must be prepended to the name. i.e. If the url * safmq://localhost was used to open the connection use * <c>"safmq://localhost/" + tmpQueue</c> when supplying * the queue name to other clients. Must be an array of atleast * one element, first element will receive the name.</param> * * <param name="tmpQueue"> [out] Receives a handle to the open queue</param> * * <returns>EC_NOERROR, EC_NETWORKERROR, EC_ALREADYDEFINED, EC_NOTAUTHORIZED</returns> */ public ErrorCode CreateTempQueue(out String tmpQueueName, QueueHandle tmpQueue) { QUEUE_CREATE_TEMP_RESPONSE resp = new QUEUE_CREATE_TEMP_RESPONSE(); resp.errorcode = ErrorCode.EC_NETWORKERROR; // flag as a network error because the first failure will be writing to the server tmpQueueName = ""; try { output.Write(Safmq.CMD_QUEUE_CREATE_TEMP); output.Flush(); resp.Read(input); if (resp.errorcode == ErrorCode.EC_NOERROR) { tmpQueueName = resp.queueName; tmpQueue.handle = resp.queueID.handle; } } catch (IOException ) { resp.errorcode = ErrorCode.EC_NETWORKERROR; } return resp.errorcode; }
/** * <summary>Gets statistics about an open queue. Places statistic information into * the parameter <c>stats</c>.</summary> * * <param name="qhandle"> Handle to an open queue</param> * <param name="includeStorageBytes"> Causes server to calculate the number of bytes on disk</param> * <param name="includeMessageBytes"> Causes the server to calculate the number of bytes in queue, * may be less than bytes on disk</param> * <param name="stats"> Receives the statistics information.</param> * <returns> Safmq.EC_NOERROR on success <br/> * Safmq.EC_NETWORKERROR<br/> * Safmq.EC_NOTOPEN </returns> */ public ErrorCode GetQueueStatistics(QueueHandle qhandle, bool includeStorageBytes, bool includeMessageBytes, out QueueStatistics stats) { QUEUE_STATS_PARAMS parms = new QUEUE_STATS_PARAMS(qhandle, includeStorageBytes, includeMessageBytes); QUEUE_STATS_RESPONSE response = new QUEUE_STATS_RESPONSE(); response.stats = stats = new QueueStatistics(); try { output.Write(Safmq.CMD_QUEUE_STATS); parms.Write(output); output.Flush(); response.Read(input); } catch (IOException ) { response.errorcode = ErrorCode.EC_NETWORKERROR; } return response.errorcode; }
/** * <summary> * Attempts to locate the messaged indicated by <c>id</c>. If the message * is succesfully located, the cursor will point to the message idenfified * and the message may be retrieved there after. * </summary> * * <param name="qhandle"> A handle to a queue previously opened by a call to OpenQueue(string)</param> * <param name="id"> The recipt UUID of the message to be located </param> * <param name="timeoutseconds">The maximum number of seconds the call should be allowed * before resulting in a "timeout".</param> * <param name="cursorID"> The cursor which should be be assigned the position * of the message indicated by <c>id</c></param> * * <returns><c>ErrorCode.EC_NOERROR</c> upon success, otherwise errors returned * could be but are not limited to:<br/> * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td> * <td>The user is not authorized to Read messages from this * queue. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td> * <td>The queue specified has not been opened by this connection. * </td></tr> * <tr><td><c>ErrorCode.EC_CURSORINVALIDATED</c></td> * <td>The cursor is no longer valid. * </td></tr> * </table> * </returns> * * <seealso cref="OpenQueue(string, QueueHandle)"/> */ public ErrorCode SeekID(QueueHandle qhandle, UUID id, int timeoutseconds, CursorHandle cursorID) { ErrorCode ret = ErrorCode.EC_NOERROR; SEEK_ID_PARAMS parms = new SEEK_ID_PARAMS(); parms.queueID = qhandle; parms.cursorID = cursorID; parms.reciptID = id; parms.timeoutseconds = timeoutseconds; try { output.Write(Safmq.CMD_SEEK_ID); parms.Write(output); output.Flush(); ret = getResponseCode(); } catch (Exception) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }
/** * <summary> * Internal method which acknowledges the reception of data from a "Retrieve" * operation. * </summary> * * <param name="qhandle"> The queue being utilized</param> * <param name="msg"> The message that was retrieved</param> * * <returns>The error response code from the server.</returns> * * <exception cref="Exception">In the case of a network error.</exception> */ ErrorCode ackRetrieveCursor(QueueHandle qhandle, QueueMessage msg) { RETRIEVE_ACK_PARAMS parms = new RETRIEVE_ACK_PARAMS(); parms.queueID = qhandle; parms.msgID = msg.MessageID; output.Write(Safmq.CMD_RETRIEVE_CURSOR_ACK); parms.Write(output); output.Flush(); return getResponseCode(); }
/** * <summary> * Retrieves the message pointed to by <c>cursorID</c>. The results * are placed in the object <c>msg</c>. * </summary> * * <remarks> * <para>Note: Retrieved messages are removed from the queue.</para> * </remarks> * * <param name="qhandle"> A handle to a queue previously opened by a call to OpenQueue(string)</param> * <param name="retrievebody"> A flag indicating whether the body of the message should be retrieved</param> * <param name="cursorID"> The cursor indicating the current position in the queue to be Read from</param> * <param name="msg"> Receives the contents of the message.</param> * * <returns>Upon success a value of <c>ErrorCode.EC_NOERROR</c>, otherwise * errors such as but not limited to could occur: <br/> * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_NOMOREMESSAGES</c></td> * <td>The queue is empty and no more messages are * available. * </td></tr> * <tr><td><c>ErrorCode.EC_ALREADYCLOSED</c></td> * <td>The queue reference is not valid as it has * been closed. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td> * <td>The user is not authorized to Read messages from this * queue. * </td></tr> * <tr><td><c>ErrorCode.EC_CURSORINVALIDATED</c></td> * <td>The cursor nolonger points to a valid location in the * queue. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td> * <td>The queue specified has not been opened by this connection. * </td></tr> * </table> * </returns> * * <seealso cref="OpenQueue(string, QueueHandle)"/> */ public ErrorCode RetrieveCursor(QueueHandle qhandle, bool retrievebody, CursorHandle cursorID, QueueMessage msg) { ErrorCode ret = ErrorCode.EC_NOERROR; PEEK_CURSOR_RETRIEVE_CURSOR_PARAMS parms = new PEEK_CURSOR_RETRIEVE_CURSOR_PARAMS(); parms.queueID = qhandle; parms.retrievebody = (byte)(retrievebody?1:0); parms.cursorID = cursorID; try { output.Write(Safmq.CMD_RETRIEVE_CURSOR); parms.Write(output); output.Flush(); ret = getResponseCode(); if (ret == ErrorCode.EC_NOERROR) { msg.Read(input,retrievebody); ret = ackRetrieveCursor(qhandle,msg); } } catch (Exception) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }
/** * <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="qhandle"> A handle to a queue previously opened by a call to OpenQueue(string)</param> * <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="timeoutseconds"> * 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>ErrorCode.EC_NOERROR</c>, otherwise * errors such as but not limited to could occur: <br/> * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_NOMOREMESSAGES</c></td> * <td>The queue is empty and no more messages are * available. * </td></tr> * <tr><td><c>ErrorCode.EC_ALREADYCLOSED</c></td> * <td>The queue reference is not valid as it has * been closed. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td> * <td>The user is not authorized to Read messages from this * queue. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td> * <td>The queue specified has not been opened by this connection. * </td></tr> * <tr><td><c>ErrorCode.EC_TIMEDOUT</c></td> * <td>The operation timed out before a message became available. * </td></tr> * </table> * </returns> * * <seealso cref="Enqueue(QueueHandle, QueueMessage)"/> * <seealso cref="OpenQueue(string, QueueHandle)"/> */ public ErrorCode RetrieveID(QueueHandle qhandle, bool retrievebody, UUID id, int timeoutseconds, QueueMessage msg) { ErrorCode ret = ErrorCode.EC_NOERROR; RETRIEVE_ID_PEEK_ID_PARAMS parms = new RETRIEVE_ID_PEEK_ID_PARAMS(); parms.queueID = qhandle; parms.retrievebody = (byte)(retrievebody?1:0); parms.reciptID = id; parms.timeoutseconds = timeoutseconds; try { output.Write(Safmq.CMD_RETRIEVE_ID); parms.Write(output);output.Flush(); ret = getResponseCode(); if (ret == ErrorCode.EC_NOERROR) { msg.Read(input,retrievebody); ret = ackRetrieveCursor(qhandle,msg); } } catch (IOException) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }
/** * <summary> * Gathers the highest priority FIFO message present on the queue. The results * are placed in the object <c>msg</c>. Any errors from the operation are * returned on the stack. The message retrieved is <i>not</i> remvoed from the * queue and is available for reading by other queue readers. * </summary> * * <param name="qhandle"> A handle to a queue previously opened by a call to OpenQueue(string)</param> * <param name="retrievebody"> A flag indicating whether the body of the message should be retrieved</param> * <param name="timeoutseconds">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>ErrorCode.EC_NOERROR</c>, otherwise * errors such as but not limited to could occur: <br/> * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_NOMOREMESSAGES</c></td> * <td>The queue is empty and no more messages are * available. * </td></tr> * <tr><td><c>ErrorCode.EC_ALREADYCLOSED</c></td> * <td>The queue reference is not valid as it has * been closed. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td> * <td>The user is not authorized to Read messages from this * queue. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td> * <td>The queue specified has not been opened by this connection. * </td></tr> * <tr><td><c>ErrorCode.EC_TIMEDOUT</c></td> * <td>The operation timed out before a message became available. * </td></tr> * </table> * </returns> * * <seealso cref="OpenQueue(string, QueueHandle)"/> */ public ErrorCode PeekFront(QueueHandle qhandle, bool retrievebody, int timeoutseconds, QueueMessage msg) { ErrorCode ret = ErrorCode.EC_NOERROR; RETRIEVE_PEEK_FRONT_PARAMS parms = new RETRIEVE_PEEK_FRONT_PARAMS(); parms.queueID = qhandle; parms.retrievebody = (byte)(retrievebody?1:0); parms.timeoutseconds = timeoutseconds; try { output.Write(Safmq.CMD_PEEK_FRONT); parms.Write(output); output.Flush(); ret = getResponseCode(); if (ret == ErrorCode.EC_NOERROR) msg.Read(input,retrievebody); } catch (Exception) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }
/** * <summary> * Opens a queue for reading and writing. The queue is then after * referenced by the parameter <c>handle</c> for calls such as * <c>Enqueue(QueueHandle,QueueMessage)</c> and * <c>Retrieve(QueueHandle,bool,int,QueueMessage)</c>. * </summary> * * <remarks> * <para><b>Note</b>: Queues which have been opened by a call to <c>OpenQueue()</c> * must be closed by a cll to <c>CloseQueue(QueueHandle)</c> if the queue * is not closed, resources allocated by a call to <c>OpenQueue()</c> * will not be released.</para> * </remarks> * * <param name="queuename">The name of the queue</param> * <param name="handle">Receives a reference to the queue</param> * * <returns><c>ErrorCode.EC_NOERROR</c> on success otherwise errors such as these, but * not limited to could be produced: * * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_DOESNOTEXIST</c></td> * <td>The queue does not exist on the server specified. * </td></tr> * </table> * </returns> * * <see cref="CloseQueue(QueueHandle)">CloseQueue(QueueHandle handle)</see> */ public ErrorCode OpenQueue(string queuename, QueueHandle handle) { ErrorCode ret; QUEUE_OPEN_QUEUE_DELETE_QUEUE_CREATE_QUEUE_ENUM_PERMS_PARAMS qOpenParam = new QUEUE_OPEN_QUEUE_DELETE_QUEUE_CREATE_QUEUE_ENUM_PERMS_PARAMS(); qOpenParam.queuename = queuename; try { output.Write(Safmq.CMD_QUEUE_OPEN); qOpenParam.Write(output); output.Flush(); ret = getResponseCode(); if (ret == ErrorCode.EC_NOERROR) { handle.handle = input.ReadInt32(); } } catch (Exception) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }
/** * <summary> * Opens a cursor for sequential reading of the queue. The newly opened * cursor points to the oldest, highest priority message in the queue. * </summary> * * <remarks> * <para>Cursors may be used to violate the priority FIFO nature of the queue * by scanning the queue and only retreiving messages which meet the * criteria of the reader. Cursor access is sequential when used in conjunction * with <c>AdvanceCursor(CursorHandle)</c>, however specific messages may * be sought out by a call to <c>SeekID(UUID,int,CursorHandle)</c>. </para> * </remarks> * * <param name="qhandle"> A handle to a queue previously opened by a call to OpenQueue(string)</param> * <param name="cursorID"> A previously allocated reference to a <c>CursorHandle</c> * which will receive the reference to the cursor.</param> * <returns><c>ErrorCode.EC_NOERROR</c> upon success, otherwise errors returned * could be but are not limited to:<br/> * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td> * <td>The user is not authorized to Read messages from this * queue. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td> * <td>The queue specified has not been opened by this connection. * </td></tr> * </table> * </returns> * * <seealso cref="OpenQueue(string, QueueHandle)"/> */ public ErrorCode OpenCursor(QueueHandle qhandle, CursorHandle cursorID) { ErrorCode ret = ErrorCode.EC_NOERROR; QUEUE_CLOSE_OPEN_CURSOR_PARAMS parms = new QUEUE_CLOSE_OPEN_CURSOR_PARAMS(); parms.queueID = qhandle; try { output.Write(Safmq.CMD_OPEN_CURSOR); parms.Write(output); output.Flush(); ret = getResponseCode(); if (ret == ErrorCode.EC_NOERROR) { cursorID.handle = input.ReadInt32(); } } catch (Exception) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }
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(); } }
/** * <summary> * Closes a cursor when it is nolonger needed to access the queue. The * cursor is invalidated after a call to <c>CloseCursor()</c> and * should not be used again. * </summary> * * <param name="qhandle"> A handle to a queue previously opened by a call to OpenQueue(string)</param> * <param name="cursorID"> The cursor to be closed.</param> * * <returns><c>ErrorCode.EC_NOERROR</c> upon success, otherwise errors returned * could be but are not limited to:<br/> * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td> * <td>The user is not authorized to Read messages from this * queue. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td> * <td>The queue specified has not been opened by this connection. * </td></tr> * </table> * </returns> * * <seealso cref="OpenQueue(string, QueueHandle)"/> */ public ErrorCode CloseCursor(QueueHandle qhandle, CursorHandle cursorID) { ErrorCode ret = ErrorCode.EC_NOERROR; CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS parms = new CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS(); parms.queueID = qhandle; parms.cursorID = cursorID; try { output.Write(Safmq.CMD_CLOSE_CURSOR); parms.Write(output); output.Flush(); ret = getResponseCode(); } catch (Exception) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }
public void test_Transactions() { 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, 10, 0); ec = con.BeginTransaction(); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to BeginTransaction:" + ec); CursorHandle cur = new CursorHandle(); ec = con.OpenCursor(handle, cur); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to OpenCursor:" + ec); ec = con.AdvanceCursor(handle, cur); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to AdvanceCursor:" + ec); ec = con.AdvanceCursor(handle, cur); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to AdvanceCursor:" + ec); QueueMessage msg = new QueueMessage(); ec = con.RetrieveCursor(handle, true, cur, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec); string txt = (new StreamReader(msg.Stream)).ReadLine(); Assert.IsTrue(txt.Equals("2"), "Incorrect Message: " + txt + " should be 2"); msg = new QueueMessage(); ec = con.RetrieveCursor(handle, true, cur, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec); txt = (new StreamReader(msg.Stream)).ReadLine(); Assert.IsTrue(txt.Equals("3"), "Incorrect Message: " + txt + " should be 3"); msg = new QueueMessage(); ec = con.Retrieve(handle, true, 0, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec); txt = (new StreamReader(msg.Stream)).ReadLine(); Assert.IsTrue(txt.Equals("0"), "Incorrect Message: " + txt + " should be 0"); int[] ids = { 1, 4, 5, 6, 7, 8, 9 }; for(int x=0;x<ids.Length;x++) { msg = new QueueMessage(); ec = con.Retrieve(handle, true, 0, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec); txt = (new StreamReader(msg.Stream)).ReadLine(); Console.WriteLine("txt: " + txt); Assert.IsTrue(int.Parse(txt) == ids[x], "Incorrect Message: " + txt + " should be " + ids[x]); } ec = con.RollbackTransaction(); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RollbackTransaction:" + ec); for(int x=0;x<8;x++) { msg = new QueueMessage(); ec = con.Retrieve(handle, true, 0, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec); txt = (new StreamReader(msg.Stream)).ReadLine(); Assert.IsTrue(int.Parse(txt) == x, "Incorrect Message: " + txt + " should be " + x); } ec = con.CommitTransaction(); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to CommitTransaction:" + ec); for(int x=0;x<2;x++) { msg = new QueueMessage(); ec = con.Retrieve(handle, true, 0, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec); txt = (new StreamReader(msg.Stream)).ReadLine(); Assert.IsTrue(int.Parse(txt) == x + 8, "Incorrect Message: " + txt + " should be " + (x + 8)); } ec = con.RollbackTransaction(); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RollbackTransaction:" + ec); ec = con.EndTransaction(); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RollbackTransaction:" + ec); for(int x=0;x<2;x++) { msg = new QueueMessage(); ec = con.Retrieve(handle, true, 0, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec); txt = (new StreamReader(msg.Stream)).ReadLine(); Assert.IsTrue(int.Parse(txt) == x + 8, "Incorrect Message: " + txt + " should be " + (x + 8)); } msg = new QueueMessage(); ec = con.Retrieve(handle, true, 0, msg); Assert.IsTrue(ec == ErrorCode.EC_NOMOREMESSAGES, "Able to RetrieveCursor:" + ec); ec = con.CloseQueue(handle); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to CloseQueue:" + ec); } finally { if (con != null) con.Close(); } }
/** * <summary> * Closes a queue which was previously opened. * </summary> * * <param name="handle"> Reference to the previously opened queue</param> * * <returns><c>ErrorCode.EC_NOERROR</c> on success otherwise errors such as these, but * not limited to could be produced: * * <table border="0" cellpadding="3" cellspacing="0"> * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td> * <td>A networking error has occurred and the conneciton * is nolonger valid. * </td></tr> * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td> * <td>The queue was not currently input an open status input the * context of this connection. * </td></tr> * </table> * </returns> */ public ErrorCode CloseQueue(QueueHandle handle) { ErrorCode ret = ErrorCode.EC_NOERROR; QUEUE_CLOSE_OPEN_CURSOR_PARAMS parms = new QUEUE_CLOSE_OPEN_CURSOR_PARAMS(); parms.queueID = handle; try { output.Write(Safmq.CMD_QUEUE_CLOSE); parms.Write(output); output.Flush(); ret = getResponseCode(); } catch (Exception ) { ret = ErrorCode.EC_NETWORKERROR; } return ret; }
void sendMessages(MQConnection con, QueueHandle handle, int count, int idxStart) { QueueMessage msg; ErrorCode ec; for(int x=0;x<count;x++) { msg = new QueueMessage(); StreamWriter w = new StreamWriter(msg.Stream); w.WriteLine((x + idxStart)); w.Close(); ec = con.Enqueue(handle, msg); Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to send message: " + (x + idxStart) + " ec: " + ec); } }
public QUEUE_STATS_PARAMS(QueueHandle qh, bool includeStorageBytes, bool includeMessageBytes) { queueID = qh.handle; this.includeStorageBytes = (byte)(includeStorageBytes ? 1 : 0); this.includeMessageBytes = (byte)(includeMessageBytes ? 1 : 0); }