/// <summary> /// Send message to existing queue from json format. /// </summary> /// <param name="meta">contain the queue general data for exemple:queue path , queue name.</param> /// <param name="body">the body as string to insert to the queue</param> /// <returns>ResultModel:show the status of the request.</returns> internal ResultModel SendJsonRequestToQueue(MSMQMeta meta, string body) { ResultModel resultModel = new ResultModel(); try { System.Messaging.MessageQueue myQueue = new System.Messaging.MessageQueue(meta.Path); myQueue.Formatter = new ActiveXMessageFormatter(); System.Messaging.Message MyMessage = MessageConvert.ConvertStringToSystemMessage(body, meta.FormmaterName, meta.Label); myQueue.Send(MyMessage); _logger.LogDebug(string.Format("Added json message to Queue:{0}", meta.Path)); resultModel.Result = (int)ResultsEnum.AddedToQueue; } catch (System.Messaging.MessageQueueException ex) { KubeMQ.MSMQSDK.Results.MessageQueueException messageEx = new KubeMQ.MSMQSDK.Results.MessageQueueException(ex); _logger.LogCritical("Failed Sending json Message to queue {0} on exception {1}", meta.Path, ex.Message); resultModel.Result = (int)ResultsEnum.Error; resultModel.exception = messageEx; } catch (Exception ex) { resultModel.Result = (int)ResultsEnum.Error; _logger.LogCritical("Failed Sending json Message to queue {0} on exception {1}", meta.Path, ex.Message); resultModel.exception = ex; } return(resultModel); }
// // Summary: // Deletes a queue on a Message Queuing server. // // Parameters: // path: // The location of the queue to be deleted. // // Exceptions: // T:System.ArgumentException: // The path parameter is null or is an empty string (""). // // T:System.Messaging.MessageQueueException: // The syntax for the path parameter is not valid.-or- An error occurred when accessing // a Message Queuing method. public static void Delete(string path) { try { MSMQMeta meta = new MSMQMeta("Delete", path, "N/A"); ResultModel resultModel = _KubeMSMQInitiator.SendRequest(meta); } catch (Exception ex) { throw ex.GetBaseException(); } }
// Summary: // Deletes all the messages contained in the queue. // // Exceptions: // T:System.Messaging.MessageQueueException: // An error occurred when accessing a Message Queuing method. public void Purge() { try { MSMQMeta meta = new MSMQMeta("Purge", this.Path, "NA"); ResultModel resultModel = _KubeMSMQInitiator.SendRequest(meta); } catch (Exception ex) { throw ex.GetBaseException(); } }
// // Summary: // Occurs when a message has been removed from the queue. This event is raised by // the asynchronous operation, System.Messaging.MessageQueue.BeginReceive. #endregion #region Simplecalls // // Summary: // Sends an object to non-transactional queue referenced by this System.Messaging.MessageQueue. // // Parameters: // obj: // The object to send to the queue. // // Exceptions: // T:System.Messaging.MessageQueueException: // The System.Messaging.MessageQueue.Path property has not been set.-or- An error // occurred when accessing a Message Queuing method. public void Send(object obj) { try { MSMQMeta meta = new MSMQMeta("Send", this.Path, "N/A"); ResultModel resultModel = _KubeMSMQInitiator.SendWithObj(obj, meta); } catch (Exception ex) { throw ex.GetBaseException(); } }
public void BeginReceive() { try { MSMQMeta meta = new MSMQMeta("BeginReceive", this.Path, "N/A"); ResultModel resultModel = _KubeMSMQInitiator.EventRequest(meta); } catch (Exception ex) { throw ex.GetBaseException(); } }
public Message Peek() { try { MSMQMeta meta = new MSMQMeta("Peek", this.Path, "N/A"); ResultModel resultModel = _KubeMSMQInitiator.SendRequest(meta); Message message = resultModel.message as Message; return message; } catch (Exception ex) { throw ex.GetBaseException(); } }
// // Summary: // Determines whether a Message Queuing queue exists at the specified path. // // Parameters: // path: // The location of the queue to find. // // Returns: // true if a queue with the specified path exists; otherwise, false. // // Exceptions: // T:System.ArgumentException: // The path syntax is not valid. // // T:System.Messaging.MessageQueueException: // An error occurred when accessing a Message Queuing method.-or- The System.Messaging.MessageQueue.Exists(System.String) // method is being called on a remote private queue // // T:System.InvalidOperationException: // The application used format name syntax when verifying queue existence. public static bool Exists(string path) { try { MSMQMeta meta = new MSMQMeta("Exists", path, "N/A"); ResultModel response = _KubeMSMQInitiator.SendRequest(meta); if (response.Result == (int)ResultsEnum.AlreadyExist || response.Result == (int)ResultsEnum.Created) { return true; } } catch (Exception ex) { throw ex.GetBaseException(); } return false; }
// // Summary: // Creates a non-transactional Message Queuing queue at the specified path. // // Parameters: // path: // The path of the queue to create. // // Returns: // A System.Messaging.MessageQueue that represents the new queue. // // Exceptions: // T:System.ArgumentException: // The path parameter is null or is an empty string (""). // // T:System.Messaging.MessageQueueException: // A queue already exists at the specified path.-or- An error occurred when accessing // a Message Queuing method. public static MessageQueue Create(string path) { try { MSMQMeta meta = new MSMQMeta("Create", path, "N/A"); ResultModel response = _KubeMSMQInitiator.SendRequest(meta); if (response.Result == (int)ResultsEnum.AlreadyExist) { } } catch (Exception ex) { throw ex.GetBaseException(); } MessageQueue messageq = new MessageQueue(path); return messageq; }
/// <summary> /// Get request from KubeMQ and run the appropriate method /// </summary> /// <param name="request"></param> /// <returns></returns> private Response HandleIncomingRequest(RequestReceive request) { ResultModel result = new ResultModel(); KubeMQ.MSMQSDK.Messages.Message MessageBody = null; _logger.LogDebug("Received Message from {0} for: {1} ", request.ReplyChannel, request.Metadata); try { _logger.LogInformation("Started Converting Object to request Message"); MSMQMeta meta = new MSMQMeta(); meta = meta.FromString(request.Metadata); switch (meta.ActionType) { case "Exists": result = common.Exists(meta.Path); break; case "Create": result = common.CreateQueue(meta.Path); break; case "Purge": result = common.PurgeQueue(meta.Path); break; case "Delete": result = common.DeleteQueue(meta.Path); break; case "Send": MessageBody = Converter.FromByteArray(request.Body) as KubeMQ.MSMQSDK.Messages.Message; result = common.SendToQueue(meta, MessageBody); break; case "Peek": result = common.PeekQueue(meta.Path); break; case "RegisterPeek": result = common.PeekEvent(meta.Path, meta.ChannelToReturn); break; case "UnRegisterPeek": result = common.UnregisterPeek(meta.Path); break; case "BeginPeek": result = common.BeginPeek(meta.Path); break; case "RegisterReceive": result = common.EventReceive(meta.Path, meta.ChannelToReturn); break; case "UnRegisterRecieve": result = common.UnregisterReceive(meta.Path); break; case "BeginReceive": result = common.BeginRecieve(meta.Path); break; case "SendJson": string str = System.Text.Encoding.Default.GetString(request.Body); result = common.SendJsonRequestToQueue(meta, str); break; } if (result.exception != null) { return(new Response(request) { Metadata = "Error", Body = Converter.ToByteArray(result), CacheHit = false, ClientID = clientID, Error = result.exception.ToString(), Executed = false }); } else { return(new Response(request) { Metadata = "Ok", Body = Converter.ToByteArray(result), CacheHit = false, ClientID = clientID, Executed = true, Error = "none" }); } } catch (ArgumentException ex) { _logger.LogCritical(ex.ToString()); return(null); } catch (Exception ex) { _logger.LogCritical(ex.ToString()); return(null); } }