public RawEndpointConfiguration CreateFailedAuditsSender(string name)
        {
            var config = RawEndpointConfiguration.CreateSendOnly(name);

            transportCustomization.CustomizeRawSendOnlyEndpoint(config, transportSettings);
            return(config);
        }
예제 #2
0
    public Task <ComponentRunner> CreateRunner(RunDescriptor run)
    {
        var typedScenarioContext = (TContext)run.ScenarioContext;

        var sendOnly = onMessage == null;
        var config   = sendOnly
            ? RawEndpointConfiguration.CreateSendOnly(name)
            : RawEndpointConfiguration.Create(name, (c, d) => onMessage(c, typedScenarioContext, d), "poison");

        config.AutoCreateQueue();
        configure(config);
        return(Task.FromResult <ComponentRunner>(new Runner(config, name, sendOnly,
                                                            endpoint => onStarting != null ? onStarting(endpoint, typedScenarioContext) : Task.FromResult(0),
                                                            endpoint => onStarted != null ? onStarted(endpoint, typedScenarioContext) : Task.FromResult(0))));
    }
        public WebOutboxConfiguration(string outboxEndpointName, string destinationEndpointName, string poisonMessageQueue)
        {
            _outboxEndpointConfiguration = new EndpointConfiguration(outboxEndpointName);

            _outboxEndpointConfiguration.Pipeline.Replace(
                "UnicastSendRouterConnector",
                new UnicastSendRouterConnector(_unicastRoutingTable, outboxEndpointName),
                "Routes all messages to the outbox endpoint");

            _outboxEndpointConfiguration.Pipeline.Replace(
                "OutgoingPhysicalToRoutingConnector",
                new OutgoingPhysicalToRoutingConnector(outboxEndpointName),
                "Routes all messages to the outbox endpoint");

            _outboxEndpointConfiguration.SendOnly();

            _forwarderEndpointConfiguration = RawEndpointConfiguration.Create(
                endpointName: outboxEndpointName,
                onMessage: (context, messages) => _onMessage?.Invoke(context, messages),
                poisonMessageQueue: poisonMessageQueue);

            _destinationEndpointName          = destinationEndpointName;
            _destinationEndpointConfiguration = RawEndpointConfiguration.CreateSendOnly(destinationEndpointName);
        }
예제 #4
0
        public static async Task Main(string[] args)
        {
            var nhConfig = new Configuration();

            nhConfig.SetProperty(Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
            nhConfig.SetProperty(Environment.ConnectionDriver, "NHibernate.Driver.Sql2008ClientDriver");
            nhConfig.SetProperty(Environment.Dialect, "NHibernate.Dialect.MsSql2008Dialect");
            nhConfig.SetProperty(Environment.ConnectionString, System.Environment.GetEnvironmentVariable("SQLServerConnectionString"));

            var mapper = new ModelMapper();

            mapper.AddMapping <TimeoutEntityMap>();
            var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();

            nhConfig.AddMapping(mappings);

            var sessionFactory =
                nhConfig.BuildSessionFactory();

            var senderConfig = RawEndpointConfiguration.CreateSendOnly("DUMMY");
            var transport    = senderConfig.UseTransport <SqsTransport>();

            transport.UnrestrictedDurationDelayedDelivery();

            var sender = await RawEndpoint.Start(senderConfig)
                         .ConfigureAwait(false);

            var ignoreMachineName = true; // Must be true for Sqs
            var now = DateTime.UtcNow;

            using (var session = sessionFactory.OpenStatelessSession())
            {
                var timeoutEntities = await session.Query <TimeoutEntity>().Take(100).ToListAsync();

                var transportOperations = new List <TransportOperation>();

                foreach (var timeout in timeoutEntities)
                {
                    await Console.Out.WriteLineAsync($"Id:{timeout.Id} Time:{timeout.Time:s} Destination:{timeout.Destination} {timeout.Endpoint}").ConfigureAwait(false);

                    var body        = timeout.State;
                    var headers     = ConvertStringToDictionary(timeout.Headers);
                    var timestamp   = timeout.Time;
                    var destination = timeout.Destination;
                    var id          = headers["NServiceBus.MessageId"];

                    if (ignoreMachineName)
                    {
                        var at = destination.LastIndexOf("@", StringComparison.InvariantCulture);

                        if (at != -1)
                        {
                            destination = destination.Substring(0, at);
                        }
                    }

                    var age = now - timestamp;

                    var request = new OutgoingMessage(
                        messageId: timeout.Id.ToString(),
                        headers: headers,
                        body: body
                        );

                    var operation = new TransportOperation(
                        request,
                        new UnicastAddressTag(destination)
                        , DispatchConsistency.Default, new List <DeliveryConstraint>
                    {
                        new DoNotDeliverBefore(timestamp)
                    });

                    if (age.Ticks > 0)
                    {
                        await Console.Out.WriteLineAsync($"Warning: Message {id} was scheduled for {timestamp} which passed {age} ago.")
                        .ConfigureAwait(false);
                    }

                    transportOperations.Add(operation);
                }
                await sender.Dispatch(
                    outgoingMessages : new TransportOperations(transportOperations.ToArray()),
                    transaction : new TransportTransaction(),
                    context : new ContextBag()
                    )
                .ConfigureAwait(false);
            }
        }