private void TaskProcess(int processId, SqlSettings clientSettings) { int queueCount = Queues.Length; for (int i = 0; i < 10000; ++i) { int messageId = i; var messengerClient = new Core.Services.Messenger(clientSettings, new MsSqlRepositoryFactory(clientSettings)); var request = new FatQueuePrintMessageEvent { Message = new CustomMessage {Message = $"[{processId.ToString().PadLeft(3, '0')}] - {messageId}"} }; var identity = Guid.NewGuid(); var publishSettings = new PublishSettings { Identity = identity, DelayExecutionInSeconds = i % 10 == 0 ? 30 : 0 }; Identities.Enqueue(identity); messengerClient.Publish<FatQueuePrintMessageEventHandler>(handler => handler.Handle(request), new QueueName(Queues[processId % queueCount]), publishSettings); } }
public void Execute(SqlSettings clientSettings) { var random = new Random(); var finished = false; while (!finished) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.Escape) { finished = true; } else { var messengerClient = new Core.Services.Messenger(clientSettings, new MsSqlRepositoryFactory(clientSettings)); //var messengerClient = new Core.Services.Messenger(clientSettings, new PostgreSqlRepositoryFactory(clientSettings)); int delayExecution = 0; Guid? identity = null; int queueIndex; if (key.KeyChar >= '0' && key.KeyChar <= '9') { queueIndex = (key.KeyChar-'0'); delayExecution = 30; identity = Guid.NewGuid(); Identities.Enqueue(identity.Value); } else if (key.Key == ConsoleKey.Delete) { var identityToCancel = Identities.Dequeue(); var canceled = messengerClient.Cancel(identityToCancel); if (canceled) { Console.WriteLine("Canceled: {0}", identityToCancel); } else { Console.WriteLine("Unable to cancel anymore: {0}", identityToCancel); } continue; } else { queueIndex = random.Next(0, Queues.Length); } var queueName = Queues[queueIndex]; var publishSettings = new PublishSettings { DelayExecutionInSeconds = delayExecution, Identity = identity }; var request = new FatQueuePrintMessageEvent { Message = new CustomMessage { Message = "Published from main manually. Delay: " + delayExecution } }; messengerClient.Publish<FatQueuePrintMessageEventHandler>(handler => handler.Handle(request), new QueueName(queueName), publishSettings); Console.WriteLine("Message published to queue {0}", queueName); } } }