public override void ConsumeData() { try { using (var connection = RabbitMQConnectionHelper.GetConnection()) { using (var channel = connection.CreateModel()) { //ustalamy,że będzie pobierał jeden item z kolejki i przetwarzał channel.BasicQos(0, 1, false); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { HandleReceivedEvent(ea, channel); }; //podłączenie konsumenta do kolejki channel.BasicConsume(queue: _queueReceiveFrom, consumer: consumer); Console.ReadLine(); } } } catch (Exception e) { Console.WriteLine(e); throw e; } }
private void GetObtainedSignalsFromQueue(int countedTechnicalIndicatorsNumber) { try { using (var connection = RabbitMQConnectionHelper.GetConnection()) { using (var channel = connection.CreateModel()) { //ustalamy,że będzie pobierał jeden item z kolejki i przetwarzał channel.BasicQos(0, 1, false); for (int i = 0; i < countedTechnicalIndicatorsNumber; i++) { BasicGetResult data; do { data = channel.BasicGet(_queueReceiveFrom, false); } while (data == null); List <Signal> currentReceivedSignals = JsonSerializer.JsonStringToCollectionOfObjectsTypes <Signal>(EncryptionHelper.ByteArrayToUTF8String(data.Body)); _obtainedSignals.Add(currentReceivedSignals); Console.WriteLine("RabbitMQ Producer received signals from Consumers."); channel.BasicAck(data.DeliveryTag, false); } } } } catch (Exception e) { Console.WriteLine(e); throw; } }
public override void Process(IndicatorCalculationElements elements) { try { using (var connection = RabbitMQConnectionHelper.GetConnection()) { using (var channel = connection.CreateModel()) { //umożliwia potwierdzanie, że przesyłkę dostarczono do Exchange channel.ConfirmSelect(); //generujemy nową wiadomość GenerateAndPublishMessage(channel, elements); } } } catch (Exception e) { Console.WriteLine(e); throw e; } }