public void Init() { if (File.Exists(@"AzureDocument0.pdf")) { File.Delete(@"AzureDocument0.pdf"); } var queueName = "testqueue"; _statusQueueName = "testStatusQueue"; _server = new QueueServer(Directory.GetCurrentDirectory(), queueName, _statusQueueName); _server.Start(); }
private void btnQueneServer_Click(object sender, EventArgs e) { QueueServer <PreDataInfo> queueServer = new QueueServer <PreDataInfo>(); queueServer.IsBackground = true; queueServer.ProcessItem += new Action <PreDataInfo>(queueServer_ProcessItem); //循环入队 for (int i = 0; i < 100; i++) { queueServer.EnqueueItem(new PreDataInfo(i.ToString(), DateTimeHelper.GetServerDateTime2().ToString())); Thread.Sleep(10); } }
public void OnPause() { try { Core.Log.InfoBasic("Pausing messaging service"); _cTokenSource.Cancel(); QueueServer.StopListeners(); Core.Log.InfoBasic("Messaging service is paused"); } catch (Exception ex) { Core.Log.Write(ex); //throw; } }
public void OnContinue() { try { Core.Log.InfoBasic("Continuing messaging service"); _cTokenSource = new CancellationTokenSource(); QueueServer.StartListeners(); Core.Log.InfoBasic("Messaging service is running"); } catch (Exception ex) { Core.Log.Write(ex); //throw; } }
public void Init() { NamespaceManager namespaceManager = NamespaceManager.Create(); var queueName = "testqueue"; if (namespaceManager.QueueExists(queueName)) { namespaceManager.DeleteQueue(queueName); } _server = new QueueServer(queueName); namespaceManager.CreateQueue(new QueueDescription(queueName) { EnablePartitioning = false }); _client = QueueClient.Create(queueName, ReceiveMode.ReceiveAndDelete); }
public void OnStop() { try { _cTokenSource.Cancel(); OnFinalizing(); Core.Log.InfoBasic("Stopping messaging service"); QueueServer.StopListeners(); QueueServer.Dispose(); Processor.Dispose(); OnDispose(); Core.Log.InfoBasic("Messaging service stopped."); } catch (Exception ex) { Core.Log.Write(ex); //throw; } }
public void OnStart(string[] args) { try { Core.Log.InfoBasic("Starting messaging service"); _cTokenSource = new CancellationTokenSource(); OnInit(args); Status = new MessagingServiceStatus(this); QueueServer = GetQueueServer(); if (QueueServer is null) { throw new Exception("The queue server is null, please check the configuration file and ensure the Types assemblies are on the assembly folder."); } Processor = GetMessageProcessorAsync(QueueServer); if (Processor is null) { throw new Exception("The message processor is null, please check your GetMessageProcessor method implementation."); } if (QueueServer.ResponseServer) { QueueServer.ResponseReceived += ResponseReceivedHandler; } else { QueueServer.RequestReceived += RequestReceivedHandler; QueueServer.BeforeSendResponse += BeforeSendResponseHandler; QueueServer.ResponseSent += ResponseSentHandler; } Processor.Init(); QueueServer.StartListeners(); Core.Log.InfoBasic("Messaging service started."); } catch (Exception ex) { Core.Log.Write(ex); throw; } }
public CancelationQueueReceiver(CancelSynchronizedCollection cancelSynchronizedCollection) { _cancelSynchronizedCollection = cancelSynchronizedCollection; _queueServer = new QueueServer(CancelQueueName); _queueServer.Received += OnRecived; }
/// <inheritdoc /> /// <summary> /// On Service Start method /// </summary> /// <param name="args">Start arguments</param> public void OnStart(string[] args) { try { Core.Log.InfoBasic("Starting messaging service"); _cTokenSource = new CancellationTokenSource(); OnInit(args); Status = new MessagingServiceStatus(this); QueueServer = GetQueueServer(); if (QueueServer == null) { throw new Exception("The queue server is null, please check the configuration file and ensure the Types assemblies are on the assembly folder."); } Processor = GetMessageProcessorAsync(QueueServer); if (Processor == null) { throw new Exception("The message processor is null, please check your GetMessageProcessor method implementation."); } if (QueueServer.ResponseServer) { QueueServer.ResponseReceived += async(s, e) => { if (MessageReceived != null) { await MessageReceived.InvokeAsync(this, new MessageEventArgs(e.Message)).ConfigureAwait(false); } if (e.Message?.Body == null) { return; } ReceivedMessagesCache.TryAdd(e.Message.Body, e.Message); Status.IncrementCurrentMessagesBeingProcessed(); var sw = Stopwatch.StartNew(); try { await Processor.ProcessAsync(e.Message.Body, _cTokenSource.Token).ConfigureAwait(false); } catch (Exception ex) { Core.Log.Write(ex); Status.IncrementTotalExceptions(); } sw.Stop(); Status.ReportProcessingTime(sw.Elapsed.TotalMilliseconds); Status.DecrementCurrentMessagesBeingProcessed(); Status.IncrementTotalMessagesProccesed(); ReceivedMessagesCache.TryRemove(e.Message.Body, out object _); }; } else { QueueServer.RequestReceived += async(s, e) => { if (MessageReceived != null) { await MessageReceived.InvokeAsync(this, new MessageEventArgs(e.Request)).ConfigureAwait(false); } if (e.Request?.Body == null) { return; } ReceivedMessagesCache.TryAdd(e.Request.Body, e.Request); object result = null; Status.IncrementCurrentMessagesBeingProcessed(); var sw = Stopwatch.StartNew(); try { result = await Processor.ProcessAsync(e.Request.Body, e.ProcessResponseTimeoutCancellationToken).ConfigureAwait(false); } catch (Exception ex) { Core.Log.Write(ex); Status.IncrementTotalExceptions(); } sw.Stop(); Status.ReportProcessingTime(sw.Elapsed.TotalMilliseconds); Status.DecrementCurrentMessagesBeingProcessed(); Status.IncrementTotalMessagesProccesed(); e.Response.Body = result; ReceivedMessagesCache.TryRemove(e.Request.Body, out object _); }; QueueServer.BeforeSendResponse += async(s, e) => { if (BeforeSendMessage != null) { await BeforeSendMessage.InvokeAsync(this, new MessageEventArgs(e.Message)).ConfigureAwait(false); } }; QueueServer.ResponseSent += async(s, e) => { if (MessageSent != null) { await MessageSent.InvokeAsync(this, new MessageEventArgs(e.Message)).ConfigureAwait(false); } }; } Processor.Init(); QueueServer.StartListeners(); Core.Log.InfoBasic("Messaging service started."); } catch (Exception ex) { Core.Log.Write(ex); throw; } }