/// <summary> /// Set a custom state on the session which can be later retrieved using <see cref="GetSessionStateAsync"/> /// </summary> /// /// <param name="sessionState">A <see cref="BinaryData"/> of session state</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// /// <remarks>This state is stored on Service Bus forever unless you set an empty state on it.</remarks> /// /// <returns>A task to be resolved on when the operation has completed.</returns> public virtual async Task SetSessionStateAsync( BinaryData sessionState, CancellationToken cancellationToken = default) { Argument.AssertNotDisposed(IsClosed, nameof(ServiceBusSessionReceiver)); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); Logger.SetSessionStateStart(Identifier, SessionId); using DiagnosticScope scope = ScopeFactory.CreateScope( DiagnosticProperty.SetSessionStateActivityName, sessionId: SessionId); scope.Start(); try { await InnerReceiver.SetStateAsync(sessionState, cancellationToken).ConfigureAwait(false); } catch (Exception exception) { Logger.SetSessionStateException(Identifier, exception.ToString()); scope.Failed(exception); throw; } Logger.SetSessionStateComplete(Identifier); }
/// <summary> /// Set a custom state on the session which can be later retrieved using <see cref="GetSessionStateAsync"/> /// </summary> /// /// <param name="sessionState">A byte array of session state</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// /// <remarks>This state is stored on Service Bus forever unless you set an empty state on it.</remarks> /// /// <returns>A task to be resolved on when the operation has completed.</returns> public virtual async Task SetSessionStateAsync( byte[] sessionState, CancellationToken cancellationToken = default) { Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSessionReceiver)); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ServiceBusEventSource.Log.SetSessionStateStart(Identifier, SessionId); try { await InnerReceiver.SetStateAsync(sessionState, cancellationToken).ConfigureAwait(false); } catch (Exception exception) { ServiceBusEventSource.Log.SetSessionStateException(Identifier, exception); throw; } cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ServiceBusEventSource.Log.SetSessionStateComplete(Identifier); }