Skip to content
This repository has been archived by the owner on Aug 29, 2019. It is now read-only.

Commit

Permalink
Replace LearningTransport with NoopTransport
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanFeldman committed May 17, 2019
1 parent c78a382 commit 48d2fc1
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NServiceBus.Extensibility;
using NServiceBus.Transport;
using NServiceBus.Configuration.AdvancedExtensibility;
Expand All @@ -21,8 +20,8 @@ public FunctionsAwareServiceBusEndpointNoTransport(string endpointName)
endpointConfiguration = new EndpointConfiguration(endpointName);
endpointConfiguration.GetSettings().Set("hack-do-not-use-the-pump", true);

transport = endpointConfiguration.UseTransport<LearningTransport>(); // TODO: create an "in-memory" transport?
transport.StorageDirectory(".");
transport = endpointConfiguration.UseTransport<NoopTransport>();
transport.ConnectionString("no-op");

Routing = transport.Routing();
}
Expand Down Expand Up @@ -82,7 +81,7 @@ Task<IEndpointInstance> InitializeEndpoint(ILogger logger, ExecutionContext exec

EndpointConfiguration endpointConfiguration;
IEndpointInstance endpointInstance;
TransportExtensions<LearningTransport> transport;
TransportExtensions<NoopTransport> transport;
}

class FakeCollector<T> : IAsyncCollector<T>
Expand Down
118 changes: 118 additions & 0 deletions NServiceBus.AzureFuntions/NoopTransport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
namespace NServiceBus
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DelayedDelivery;
using Extensibility;
using Performance.TimeToBeReceived;
using Routing;
using Settings;
using Transport;

public class NoopTransport : TransportDefinition
{
public override string ExampleConnectionStringForErrorMessage { get; } = string.Empty;

public override TransportInfrastructure Initialize(SettingsHolder settings, string connectionString)
{
return new NoopTransportInfrastructure();
}
}

class NoopTransportInfrastructure : TransportInfrastructure
{
public override IEnumerable<Type> DeliveryConstraints
{
get
{
yield return typeof(DelayDeliveryWith);
yield return typeof(NonDurableDelivery);
yield return typeof(DoNotDeliverBefore);
yield return typeof(DelayedDeliveryConstraint);
yield return typeof(DiscardIfNotReceivedBefore);
}
}

public override TransportTransactionMode TransactionMode { get; } = TransportTransactionMode.None;

public override OutboundRoutingPolicy OutboundRoutingPolicy { get; } = new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Multicast, OutboundRoutingType.Unicast);

public override TransportReceiveInfrastructure ConfigureReceiveInfrastructure()
{
return new TransportReceiveInfrastructure(
messagePumpFactory:() => new NoOpPump(),
queueCreatorFactory:() => new NoOpQueueCreator(),
preStartupCheck: () => Task.FromResult(StartupCheckResult.Success));
}

public override TransportSendInfrastructure ConfigureSendInfrastructure()
{
return new TransportSendInfrastructure(
dispatcherFactory: () => new NoOpMessageDispatcher(),
preStartupCheck: () => Task.FromResult(StartupCheckResult.Success));
}

public override TransportSubscriptionInfrastructure ConfigureSubscriptionInfrastructure()
{
return new TransportSubscriptionInfrastructure(
subscriptionManagerFactory: () => new NoOpSubscriptionManager());
}

public override EndpointInstance BindToLocalEndpoint(EndpointInstance instance)
{
return new EndpointInstance(instance.Endpoint);
}

public override string ToTransportAddress(LogicalAddress logicalAddress)
{
return logicalAddress.EndpointInstance.Endpoint;
}
}

class NoOpSubscriptionManager : IManageSubscriptions
{
public Task Subscribe(Type eventType, ContextBag context)
{
return Task.CompletedTask;
}

public Task Unsubscribe(Type eventType, ContextBag context)
{
return Task.CompletedTask; ;
}
}

class NoOpMessageDispatcher : IDispatchMessages
{
public Task Dispatch(TransportOperations outgoingMessages, TransportTransaction transaction, ContextBag context)
{
return Task.CompletedTask;
}
}

class NoOpQueueCreator : ICreateQueues
{
public Task CreateQueueIfNecessary(QueueBindings queueBindings, string identity)
{
return Task.CompletedTask;
}
}

class NoOpPump : IPushMessages
{
public Task Init(Func<MessageContext, Task> onMessage, Func<ErrorContext, Task<ErrorHandleResult>> onError, CriticalError criticalError, PushSettings settings)
{
return Task.CompletedTask;
}

public void Start(PushRuntimeSettings limitations)
{
}

public Task Stop()
{
return Task.CompletedTask;
}
}
}

0 comments on commit 48d2fc1

Please sign in to comment.