Beispiel #1
0
        public void Publish_ThrowsArgumentWhenBodyNull()
        {
            byte[] body       = null;
            string routingKey = null;

            Assert.ThrowsException <ArgumentException>(() =>
                                                       subject.Publish(body, routingKey));
        }
Beispiel #2
0
        public async Task <ICollection <FileDto> > GetFiles(bool rescan)
        {
            if (rescan)
            {
                var(added, deleted, total) = await Rescan();

                _rabbitPublisher.Publish <SynchronizedEventMessage>(new SynchronizedEventMessage
                {
                    TotalNow = total,
                    Added    = added,
                    Deleted  = deleted
                });
            }

            return(_context.Files.ToList().ToDtoCollection(await _storage.GeneratePath("")));
        }
Beispiel #3
0
        private void SendAnswer(string message)
        {
            var connection = RabbitConnector.GetConnection();
            var settings   = new QueryExecutorRabbitSettings();

            RabbitPublisher.Publish(connection, settings.ExchangeName, settings.AnswerQueueName, settings.AnswerRoutingKey, message);
        }
        //[TestMethod]
        public void IntTest()
        {
            Environment.SetEnvironmentVariable("RABBIT_PORT", "5671");

            Rabbit subject = Rabbit.Connect();

            var consumer = subject.ConsumerBuilder()
                           .SetExchange(exchange)
                           .AddQueue(queue, expectedRoutingKey)
                           .Build();

            consumer.RegisterReceiver(receiver);

            var             msg       = Encoding.UTF8.GetBytes(expectedMsg);
            RabbitPublisher publisher = subject.PublishBuilder().
                                        SetExchange(exchange)
                                        .AddQueue(queue, expectedRoutingKey)
                                        .Build();



            string routingKey = "";

            publisher.Publish(msg, routingKey);

            Thread.Sleep(sleepTimeMs);

            Assert.AreEqual(expectedMsg, actual);
        }
Beispiel #5
0
        public void Publish()
        {
            IPublisher <TestMessage> pubs = new RabbitPublisher <TestMessage>(Options);

            pubs.Init();

            var message = GetTestMessage();

            pubs.Publish(message);
        }
Beispiel #6
0
        public void Publish_DoesWait_WhenNotConfirm()
        {
            this.subject = new RabbitPublisher(mockedCreator.Object, exchange, basicProperties.Object, false);

            byte[] body       = Encoding.UTF8.GetBytes("hello");
            string routingKey = "";

            subject.Publish(body, routingKey);

            mockedChannel.Verify(c => c.WaitForConfirms(It.IsAny <TimeSpan>()), Times.Never);
        }
Beispiel #7
0
        public void Publish()
        {
            var consumer = subject.ConsumerBuilder()
                           .SetExchange(topic)
                           .AddQueue(queue, routingKey)
                           .Build();

            var             msg       = Encoding.UTF8.GetBytes(expected);
            RabbitPublisher publisher = subject.PublishBuilder().
                                        SetExchange(topic)
                                        .AddQueue(queue, routingKey)
                                        .Build();


            publisher.Publish(msg, routingKey);
        }
        public static void PublishMessageTest()
        {
            IRabbitPublisherConfiguration publishConfig = new RabbitPublisherConfiguration();
            RabbitPublisher <CommandArgs> publisher     = new RabbitPublisher <CommandArgs>(publishConfig);

            IRabbitSubscriberConfiguration subscriberConfig = new RabbitSubscriberConfiguration();
            SandboxConsumer consumer = new SandboxConsumer();

            RabbitSubscriber <SandboxConsumer> subscriber = new RabbitSubscriber <SandboxConsumer>(consumer, subscriberConfig);

            subscriber.Start();

            publisher.Publish(new CommandArgs {
                Value = "some data"
            });



            Console.ReadKey();
        }
        public void Run()
        {
            Connect();
            long sentCount = 0;

            try
            {
                for (int i = 0; i < repeatCount; i++)
                {
                    try
                    {
                        publisher.Publish(msg, routingKey);
                        sentCount++;
                        Console.WriteLine($"PRODUCER: Msg sent {message.Length} byte count {sentCount}");
                        Thread.Sleep(sleepPeriodMs);
                    }
                    catch (RabbitMQClientException rabbitException)
                    {
                        Console.WriteLine($"PRODUCER:  client exce[topm] {rabbitException}, sentCount:{sentCount} sleeping {errorSleepPeriodMs} milliseconds");
                        Thread.Sleep(errorSleepPeriodMs);
                        Console.WriteLine($"PRODUCER: WOKE after client exception {rabbitException.Message} sentCount:{sentCount}");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"PRODUCER: EXCEPTION:{e} sentCount:{sentCount} sleeping {errorSleepPeriodMs} milliseconds");
                        Thread.Sleep(errorSleepPeriodMs);
                        Console.WriteLine($"PRODUCER: WOKE after RabbitMQ exception {e.Message} sentCount:{sentCount}");
                    }
                }
                Console.WriteLine($"PRODUCER: Sent {message.Length} bytes {sentCount} time(s)");
            }
            catch (Exception e)
            {
                Console.WriteLine($"PRODUCER: EXCEPTION:{e}");
            }
        }
Beispiel #10
0
        public async Task ConvertInFormat(Guid videoFileId, VideoFormat format)
        {
            FileDbModel result;

            var conversion =
                await _context.Conversions.FirstOrDefaultAsync(c =>
                                                               c.Source.FileId == videoFileId && c.VideoFormat == format);

            if (conversion?.Status == ConversionStatus.InProgress)
            {
                return;
            }

            if (conversion?.Status == ConversionStatus.Success)
            {
                result = conversion.Result;
            }

            else
            {
                var file = await _context.Files.FirstOrDefaultAsync(f => f.FileId == videoFileId)
                           ?? throw new FileNotFoundException();

                if (conversion == null)
                {
                    conversion = new ConversionDbModel
                    {
                        Source      = file,
                        Status      = ConversionStatus.InProgress,
                        Tryes       = 1,
                        VideoFormat = format
                    };
                    _context.Add(conversion);
                }
                else
                {
                    conversion.Tryes++; //todo maxTryes
                }
                await _context.SaveChangesAsync();

                if (format == VideoFormat.preview)
                {
                    result = await GenerateFilePreview(file);
                }

                else if (format == VideoFormat.gif)
                {
                    result = await GenerateFileGif(file);
                }

                else
                {
                    result = await ConvertVideoInternal(file, format);
                }

                _context.Files.Add(result);
                _context.SaveChanges();
            }

            _rabbitPublisher.Publish <VideoConvertedEventMessage>(new VideoConvertedEventMessage
            {
                Format   = format,
                SourceId = videoFileId,
                ResultId = result.FileId
            });
        }