本文整理汇总了C#中MessageBusType类的典型用法代码示例。如果您正苦于以下问题:C# MessageBusType类的具体用法?C# MessageBusType怎么用?C# MessageBusType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageBusType类属于命名空间,在下文中一共展示了MessageBusType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReconnectExceedingReconnectWindowDisconnectsWithFastBeatInterval
public void ReconnectExceedingReconnectWindowDisconnectsWithFastBeatInterval(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
// Test cannot be async because if we do host.ShutDown() after an await the connection stops.
using (var host = CreateHost(hostType, transportType))
{
host.Initialize(keepAlive: 9, messageBusType: messageBusType);
var connection = CreateHubConnection(host);
using (connection)
{
var disconnectWh = new ManualResetEventSlim();
connection.Closed += () =>
{
disconnectWh.Set();
};
SetReconnectDelay(host.Transport, TimeSpan.FromSeconds(15));
connection.Start(host.Transport).Wait();
// Without this the connection start and reconnect can race with eachother resulting in a deadlock.
Thread.Sleep(TimeSpan.FromSeconds(3));
// Set reconnect window to zero so the second we attempt to reconnect we can ensure that the reconnect window is verified.
((Client.IConnection)connection).ReconnectWindow = TimeSpan.FromSeconds(0);
host.Shutdown();
Assert.True(disconnectWh.Wait(TimeSpan.FromSeconds(15)), "Closed never fired");
}
}
}
示例2: UseMessageBus
protected void UseMessageBus(MessageBusType type, IDependencyResolver resolver, int streams = 1)
{
IMessageBus bus = null;
switch (type)
{
case MessageBusType.Default:
break;
case MessageBusType.Fake:
case MessageBusType.FakeMultiStream:
bus = new FakeScaleoutBus(resolver, streams);
break;
case MessageBusType.SqlServer:
break;
case MessageBusType.ServiceBus:
break;
case MessageBusType.Redis:
break;
default:
break;
}
if (bus != null)
{
resolver.Register(typeof(IMessageBus), () => bus);
}
}
示例3: Initialize
public void Initialize(int? keepAlive,
int? connectionTimeout,
int? disconnectTimeout,
int? transportConnectTimeout,
bool enableAutoRejoiningGroups,
MessageBusType type = MessageBusType.Default)
{
if (type != MessageBusType.Default)
{
throw new NotImplementedException();
}
// Use a configuration file to specify values
string content = String.Format(_webConfigTemplate.Value,
keepAlive,
connectionTimeout,
disconnectTimeout,
transportConnectTimeout,
enableAutoRejoiningGroups,
_logFileName);
File.WriteAllText(_webConfigPath, content);
Url = _siteManager.GetSiteUrl(ExtraData);
}
示例4: CanInvokeMethodsAndReceiveMessagesFromValidTypedHub
public async Task CanInvokeMethodsAndReceiveMessagesFromValidTypedHub(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
using (var host = CreateHost(hostType, transportType))
{
host.Initialize(messageBusType: messageBusType);
using (var connection = CreateHubConnection(host))
{
var hub = connection.CreateHubProxy("ValidTypedHub");
var echoTcs = new TaskCompletionSource<string>();
var pingWh = new ManualResetEventSlim();
hub.On<string>("Echo", message => echoTcs.TrySetResult(message));
hub.On("Ping", pingWh.Set);
await connection.Start(host.TransportFactory());
hub.InvokeWithTimeout("Echo", "arbitrary message");
Assert.True(echoTcs.Task.Wait(TimeSpan.FromSeconds(10)));
Assert.Equal("arbitrary message", echoTcs.Task.Result);
hub.InvokeWithTimeout("Ping");
Assert.True(pingWh.Wait(TimeSpan.FromSeconds(10)));
}
}
}
示例5: SuccessiveTimeoutTest
public async Task SuccessiveTimeoutTest(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
using (var host = CreateHost(hostType, transportType))
{
// Arrange
var mre = new AsyncManualResetEvent(false);
host.Initialize(keepAlive: 5, messageBusType: messageBusType);
var connection = CreateConnection(host, "/my-reconnect");
using (connection)
{
connection.Reconnected += () =>
{
mre.Set();
};
await connection.Start(host.Transport);
((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromMilliseconds(300));
// Assert that Reconnected is called
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(15)));
// Assert that Reconnected is called again
mre.Reset();
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(15)));
// Clean-up
mre.Dispose();
}
}
}
示例6: ReconnectionSuccesfulTest
public void ReconnectionSuccesfulTest(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
using (var host = CreateHost(hostType, transportType))
{
// Arrange
var mre = new ManualResetEventSlim(false);
host.Initialize(keepAlive: null, messageBusType: messageBusType);
var connection = CreateConnection(host, "/my-reconnect");
using (connection)
{
((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromSeconds(2));
connection.Reconnected += () =>
{
mre.Set();
};
connection.Start(host.Transport).Wait();
// Assert
Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));
// Clean-up
mre.Dispose();
}
}
}
示例7: MarkActiveStopsConnectionIfCalledAfterExtendedPeriod
public void MarkActiveStopsConnectionIfCalledAfterExtendedPeriod(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
using (var host = CreateHost(hostType, transportType))
{
host.Initialize(messageBusType: messageBusType);
var connection = CreateHubConnection(host);
using (connection)
{
var disconnectWh = new ManualResetEventSlim();
connection.Closed += () =>
{
disconnectWh.Set();
};
connection.Start(host.Transport).Wait();
// The MarkActive interval should check the reconnect window. Since this is short it should force the connection to disconnect.
((Client.IConnection)connection).ReconnectWindow = TimeSpan.FromSeconds(1);
Assert.True(disconnectWh.Wait(TimeSpan.FromSeconds(15)), "Closed never fired");
}
}
}
示例8: TransportTimesOutIfNoInitMessage
public async Task TransportTimesOutIfNoInitMessage(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
var mre = new AsyncManualResetEvent();
using (var host = CreateHost(hostType, transportType))
{
host.Initialize(transportConnectTimeout: 1, messageBusType: messageBusType);
HubConnection hubConnection = CreateHubConnection(host, "/no-init");
IHubProxy proxy = hubConnection.CreateHubProxy("DelayedOnConnectedHub");
using (hubConnection)
{
try
{
await hubConnection.Start(host.Transport);
}
catch
{
mre.Set();
}
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(10)));
}
}
}
示例9: ReconnectionSuccesfulTest
public async Task ReconnectionSuccesfulTest(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
using (var host = CreateHost(hostType, transportType))
{
// Arrange
var mre = new AsyncManualResetEvent(false);
host.Initialize(keepAlive: null, messageBusType: messageBusType);
var connection = CreateConnection(host, "/my-reconnect");
if (transportType == TransportType.LongPolling)
{
((Client.Transports.LongPollingTransport)host.Transport).ReconnectDelay = TimeSpan.Zero;
}
using (connection)
{
((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromSeconds(2));
connection.Reconnected += () =>
{
mre.Set();
};
await connection.Start(host.Transport);
Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(10)));
// Clean-up
mre.Dispose();
}
}
}
示例10: Initialize
public void Initialize(int? keepAlive = -1,
int? connectionTimeout = 110,
int? disconnectTimeout = 30,
int? transportConnectTimeout = 5,
bool enableAutoRejoiningGroups = false,
MessageBusType type = MessageBusType.Default)
{
// nothing to initialize since it is external!
}
示例11: ReconnectFiresAfterHostShutdown
public async Task ReconnectFiresAfterHostShutdown(TransportType transportType, MessageBusType messageBusType)
{
var serverRestarts = 0;
var serverReconnects = 0;
var host = new ServerRestarter(app =>
{
var config = new ConnectionConfiguration
{
Resolver = new DefaultDependencyResolver()
};
UseMessageBus(messageBusType, config.Resolver);
app.MapSignalR<MyReconnect>("/endpoint", config);
serverRestarts++;
serverReconnects = 0;
config.Resolver.Register(typeof(MyReconnect), () => new MyReconnect(() => serverReconnects++));
});
using (host)
{
using (var connection = CreateConnection("http://foo/endpoint"))
{
var transport = CreateTransport(transportType, host);
var pollEvent = new AsyncManualResetEvent();
var reconnectedEvent = new AsyncManualResetEvent();
host.OnPoll = () =>
{
pollEvent.Set();
};
connection.Reconnected += () =>
{
reconnectedEvent.Set();
};
await connection.Start(transport);
// Wait for the /poll before restarting the server
Assert.True(await pollEvent.WaitAsync(TimeSpan.FromSeconds(15)), "Timed out waiting for poll request");
host.Restart();
Assert.True(await reconnectedEvent.WaitAsync(TimeSpan.FromSeconds(15)), "Timed out waiting for client side reconnect");
Assert.Equal(2, serverRestarts);
Assert.Equal(1, serverReconnects);
}
}
}
示例12: ReconnectFiresAfterHostShutdown
public void ReconnectFiresAfterHostShutdown(TransportType transportType, MessageBusType messageBusType)
{
var persistentConnections = new List<MyReconnect>();
var host = new ServerRestarter(app =>
{
var config = new ConnectionConfiguration
{
Resolver = new DefaultDependencyResolver()
};
UseMessageBus(messageBusType, config.Resolver);
app.MapSignalR<MyReconnect>("/endpoint", config);
var conn = new MyReconnect();
config.Resolver.Register(typeof(MyReconnect), () => conn);
persistentConnections.Add(conn);
});
using (host)
{
using (var connection = CreateConnection("http://foo/endpoint"))
{
var transport = CreateTransport(transportType, host);
var pollEvent = new ManualResetEventSlim();
var reconnectedEvent = new ManualResetEventSlim();
host.OnPoll = () =>
{
pollEvent.Set();
};
connection.Reconnected += () =>
{
reconnectedEvent.Set();
};
connection.Start(transport).Wait();
// Wait for the /poll before restarting the server
Assert.True(pollEvent.Wait(TimeSpan.FromSeconds(15)), "Timed out waiting for poll request");
host.Restart();
Assert.True(reconnectedEvent.Wait(TimeSpan.FromSeconds(15)), "Timed out waiting for client side reconnect");
Assert.Equal(2, persistentConnections.Count);
Assert.Equal(1, persistentConnections[1].Reconnects);
}
}
}
示例13: Initialize
public override void Initialize(int? keepAlive = -1,
int? connectionTimeout = 110,
int? disconnectTimeout = 30,
int? transportConnectTimeout = 5,
bool enableAutoRejoiningGroups = false,
MessageBusType messageBusType = MessageBusType.Default)
{
base.Initialize(keepAlive, connectionTimeout, disconnectTimeout, transportConnectTimeout, enableAutoRejoiningGroups, messageBusType);
_host.Configure(app =>
{
Initializer.ConfigureRoutes(app, Resolver);
});
}
示例14: HubProgressThrowsInvalidOperationExceptionIfAttemptToReportProgressAfterMethodReturn
public async Task HubProgressThrowsInvalidOperationExceptionIfAttemptToReportProgressAfterMethodReturn(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
using (var host = CreateHost(hostType, transportType))
{
host.Initialize(messageBusType: messageBusType);
HubConnection hubConnection = CreateHubConnection(host);
IHubProxy proxy = hubConnection.CreateHubProxy("progress");
proxy.On<bool>("sendProgressAfterMethodReturnResult", result => Assert.True(result));
using (hubConnection)
{
await hubConnection.Start(host.Transport);
await proxy.Invoke<int>("SendProgressAfterMethodReturn", _ => { });
}
}
}
示例15: TryGetMessageBusType
/// <summary>
/// Gets a message bus type based on the specified string <paramref name="value"/>.
/// </summary>
/// <param name="value">The value to convert to an message bus type (i.e., name, value or unique description).</param>
/// <param name="result">The message bus type.</param>
public static Boolean TryGetMessageBusType(String value, out MessageBusType result)
{
Int32 parsedValue;
Object boxedValue = Int32.TryParse(value, out parsedValue) ? parsedValue : (Object)value;
if (value.IsNullOrWhiteSpace())
{
result = MessageBusType.MicrosoftMessageQueuing;
return true;
}
if (Enum.IsDefined(typeof(MessageBusType), boxedValue))
{
result = (MessageBusType)Enum.ToObject(typeof(MessageBusType), boxedValue);
return true;
}
return KnownMessageBusTypes.TryGetValue(value, out result);
}