public void RegisterOnSessionHandlerStart(string clientId, SessionHandlerOptions sessionHandlerOptions) { if (this.IsEnabled()) { this.RegisterOnSessionHandlerStart(clientId, sessionHandlerOptions.AutoComplete, sessionHandlerOptions.MaxConcurrentSessions, (long)sessionHandlerOptions.MessageWaitTimeout.TotalSeconds, (long)sessionHandlerOptions.MaxAutoRenewDuration.TotalSeconds); } }
public void OnSessionHandler( Func <IMessageSession, Message, CancellationToken, Task> callback, SessionHandlerOptions sessionHandlerOptions) { MessagingEventSource.Log.RegisterOnSessionHandlerStart(this.ClientId, sessionHandlerOptions); lock (this.syncLock) { if (this.sessionReceivePump != null) { throw new InvalidOperationException(Resources.SessionHandlerAlreadyRegistered); } this.sessionPumpCancellationTokenSource = new CancellationTokenSource(); // Running task cancellation token source can be reused if previously UnregisterSessionHandlerAsync was called if (this.runningTaskCancellationTokenSource == null) { this.runningTaskCancellationTokenSource = new CancellationTokenSource(); } this.sessionReceivePump = new SessionReceivePump( this.ClientId, this.SessionClient, this.ReceiveMode, sessionHandlerOptions, callback, this.endpoint, this.sessionPumpCancellationTokenSource.Token, this.runningTaskCancellationTokenSource.Token); } try { this.sessionReceivePump.StartPump(); } catch (Exception exception) { MessagingEventSource.Log.RegisterOnSessionHandlerException(this.ClientId, exception); if (this.sessionReceivePump != null) { this.sessionPumpCancellationTokenSource.Cancel(); this.sessionPumpCancellationTokenSource.Dispose(); this.sessionReceivePump = null; } throw; } MessagingEventSource.Log.RegisterOnSessionHandlerStop(this.ClientId); }
public SessionReceivePump(string clientId, ISessionClient client, ReceiveMode receiveMode, SessionHandlerOptions sessionHandlerOptions, Func <IMessageSession, Message, CancellationToken, Task> callback, string endpoint, CancellationToken token) { this.client = client ?? throw new ArgumentException(nameof(client)); this.clientId = clientId; this.ReceiveMode = receiveMode; this.sessionHandlerOptions = sessionHandlerOptions; this.userOnSessionCallback = callback; this.endpoint = endpoint; this.entityPath = client.EntityPath; this.pumpCancellationToken = token; this.maxConcurrentSessionsSemaphoreSlim = new SemaphoreSlim(this.sessionHandlerOptions.MaxConcurrentSessions); this.maxPendingAcceptSessionsSemaphoreSlim = new SemaphoreSlim(this.sessionHandlerOptions.MaxConcurrentAcceptSessionCalls); }
public async Task OnSessionHandlerAsync( Func <IMessageSession, Message, CancellationToken, Task> callback, SessionHandlerOptions sessionHandlerOptions) { MessagingEventSource.Log.RegisterOnSessionHandlerStart(this.ClientId, sessionHandlerOptions); lock (this.syncLock) { if (this.sessionReceivePump != null) { throw new InvalidOperationException(Resources.SessionHandlerAlreadyRegistered); } this.sessionPumpCancellationTokenSource = new CancellationTokenSource(); this.sessionReceivePump = new SessionReceivePump( this.ClientId, this.SessionClient, this.ReceiveMode, sessionHandlerOptions, callback, this.sessionPumpCancellationTokenSource.Token); } try { await this.sessionReceivePump.StartPumpAsync().ConfigureAwait(false); } catch (Exception exception) { MessagingEventSource.Log.RegisterOnSessionHandlerException(this.ClientId, exception); if (this.sessionReceivePump != null) { this.sessionPumpCancellationTokenSource.Cancel(); this.sessionPumpCancellationTokenSource.Dispose(); this.sessionReceivePump = null; } throw; } MessagingEventSource.Log.RegisterOnSessionHandlerStop(this.ClientId); }
public SessionReceivePump(string clientId, ISessionClient client, ReceiveMode receiveMode, SessionHandlerOptions sessionHandlerOptions, Func <IMessageSession, Message, CancellationToken, Task> callback, Uri endpoint, CancellationToken pumpToken, CancellationToken runningTaskToken) { this.client = client ?? throw new ArgumentException(nameof(client)); this.clientId = clientId; this.ReceiveMode = receiveMode; this.sessionHandlerOptions = sessionHandlerOptions; this.userOnSessionCallback = callback; this.endpoint = endpoint.Authority; this.entityPath = client.EntityPath; this.pumpCancellationToken = pumpToken; this.runningTaskCancellationToken = runningTaskToken; this.maxConcurrentSessionsSemaphoreSlim = new SemaphoreSlim(this.sessionHandlerOptions.MaxConcurrentSessions); this.maxPendingAcceptSessionsSemaphoreSlim = new SemaphoreSlim(this.sessionHandlerOptions.MaxConcurrentAcceptSessionCalls); this.diagnosticSource = new ServiceBusDiagnosticSource(client.EntityPath, endpoint); }
/// <summary>Register a session handler.</summary> /// <param name="handler"></param> /// <param name="sessionHandlerOptions">Options associated with session pump processing.</param> public void RegisterSessionHandler(Func <IMessageSession, Message, CancellationToken, Task> handler, SessionHandlerOptions sessionHandlerOptions) { this.SessionPumpHost.OnSessionHandlerAsync(handler, sessionHandlerOptions).GetAwaiter().GetResult(); }
/// <summary>Register a session handler.</summary> /// <param name="handler"></param> public void RegisterSessionHandler(Func <IMessageSession, Message, CancellationToken, Task> handler) { var sessionHandlerOptions = new SessionHandlerOptions(); this.RegisterSessionHandler(handler, sessionHandlerOptions); }