Esempio n. 1
0
        public void SetUp(params Type[] typesToSubscribeTo)
        {
            receivedMessages = new BlockingCollection <IncomingMessage>();

            Environment.SetEnvironmentVariable("KafkaTransport.ConnectionString", "127.0.0.1:9092");
            var            connectionString = Environment.GetEnvironmentVariable("KafkaTransport.ConnectionString");//"127.0.0.1:9092"
            SettingsHolder settingsHolder   = new SettingsHolder();

            settingsHolder.Set("NServiceBus.Routing.EndpointName", endpointName);

            var kafkaTransport = new KafkaTransport();
            var infra          = kafkaTransport.Initialize(settingsHolder, connectionString);

            messageDispatcher = new MessageDispatcher(new Transports.Kafka.Connection.ProducerFactory(connectionString));


            messagePump = new MessagePump(settingsHolder, connectionString);


            subscriptionManager = new SubscriptionManager(messagePump, null);

            foreach (var t in typesToSubscribeTo)
            {
                subscriptionManager.Subscribe(t, new ContextBag());
            }


            messagePump.Init(messageContext =>
            {
                receivedMessages.Add(new IncomingMessage(messageContext.MessageId, messageContext.Headers, messageContext.Body));
                return(Task.FromResult(0));
            },
                             ErrorContext => Task.FromResult(ErrorHandleResult.Handled),
                             new CriticalError(_ => Task.FromResult(0)),
                             new PushSettings(endpointName, ErrorQueue, true, TransportTransactionMode.ReceiveOnly)
                             ).GetAwaiter().GetResult();

            messagePump.Start(new PushRuntimeSettings(MaximumConcurrency));
        }
Esempio n. 2
0
        public ITransport Create(string inputQueueAddress)
        {
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var asyncTaskFactory     = new TplAsyncTaskFactory(consoleLoggerFactory);

            if (inputQueueAddress == null)
            {
                var transport = new KafkaTransport(consoleLoggerFactory, asyncTaskFactory, null, "127.0.0.1:9092", "1", inputQueueAddress);

                transport.Initialize();

                return(transport);
            }

            return(_queuesToDelete.GetOrAdd(inputQueueAddress, () =>
            {
                var transport = new KafkaTransport(consoleLoggerFactory, asyncTaskFactory, null, "127.0.0.1:9092", "1", inputQueueAddress);

                transport.Initialize();

                return transport;
            }));
        }