SzymonPobiega / NServiceBus.Router

Cross-transport, cross-site and possibly cross-cloud router component for NServiceBus
MIT License
5 stars 10 forks source link

Azure events to SQS #14

Closed biddlem closed 5 years ago

biddlem commented 5 years ago

I am trying to setup a connection between an AzureServiceBus Publisher and an Amazon SQS Subscriber.

The following is my router code:

        static async Task Main()
        {
            Console.Title = "Demo.Router";

            var routerConfig = new RouterConfiguration("Demo.Router");

            var sqsInterface = routerConfig.AddInterface<SqsTransport>("SQS", t =>
            {
                t.ClientFactory(() =>
                    new AmazonSQSClient(
                        new BasicAWSCredentials(accessKey, accessSecret),
                        RegionEndpoint.GetBySystemName(regionName)));
            });

            var mongoDatabase = new MongoClient(connectionString).GetDatabase(MongoUrl.Create(connectionString).DatabaseName);

            sqsInterface.EnableMessageDrivenPublishSubscribe(new SubscriptionPersister(mongoDatabase));

            var azureServiceBusInterface = routerConfig.AddInterface<AzureServiceBusTransport>("ASB",
                t => {
                    t.ConnectionString(connectionString);
                    var topology = t.UseEndpointOrientedTopology();

                    topology.RegisterPublisher(typeof(ArticlePublished),
                        "queue@connectionString");

                    var sanitization = t.Sanitization();
                    sanitization.UseStrategy<Sha1Sanitization>();

                    var settings = t.GetSettings();
                    var builder = new ConventionsBuilder(settings);
                    builder.DefiningEventsAs(e =>
                        e.Namespace != null &&
                        e.Namespace.ToLowerInvariant().EndsWith("events"));

                    settings.Set<NServiceBus.Conventions>(builder.Conventions);

                    var serializer = Tuple.Create(new NewtonsoftSerializer() as SerializationDefinition, settings);
                    settings.Set("MainSerializer", serializer);
                });

            var staticRouting = routerConfig.UseStaticRoutingProtocol();

            staticRouting.AddForwardRoute("SQS", "ASB");

            routerConfig.AutoCreateQueues();
            var router = NServiceBus.Router.Router.Create(routerConfig);

            await router.Start().ConfigureAwait(false);

            Console.WriteLine("Press <enter> to exit");
            Console.ReadLine();

            await router.Stop().ConfigureAwait(false);
        }
    }

My SQS Subscriber has the following connection to the Router:

            var bridge = transport.Routing().ConnectToRouter("Demo.Router");
                bridge.RegisterPublisher(typeof(ArticlePublished), "queue@connectionString");

I can see the SQS router queue message for "Subscribe" message intent. The Router blows up with an error when I believe it is trying to setup the subscription in AzureServiceBus:

The remote server returned an error: (400) Bad Request. The specified HTTP verb (GET) is not valid. TrackingId:XXXX, SystemTracker:YYYY:Queue:queue

Any guidance on how I am not setting this up properly would be appreciated.

SzymonPobiega commented 5 years ago

Hi @biddlem .

Sorry I missed this one. For some reason I disabled notifications for my private github account :(

I'll look into this.

SzymonPobiega commented 5 years ago

Does it work if you don't include the connection string in the RegisterPublisher call i.e. when the Router and the ASB publisher use the same namespace?

biddlem commented 5 years ago

I resolved the issue yesterday, it ended up being an issue with the destination I was configuring in the router; in NServiceBus 5 we were able to subscribe to events by specifying a destination "queue@namespace", but in NServiceBus 7 I needed to specify the "topic@namespace"