private void StartSubscription(StartSubscriptionMessage msg) { switch (_state) { case ConnectionState.Init: msg.Source.SetException(new InvalidOperationException(string.Format("EventStoreConnection '{0}' is not active.", _esConnection.ConnectionName))); break; case ConnectionState.Connecting: case ConnectionState.Connected: var operation = new SubscriptionOperation(_settings.Log, msg.Source, msg.StreamId, msg.ResolveLinkTos, msg.UserCredentials, msg.EventAppeared, msg.SubscriptionDropped, _settings.VerboseLogging, () => _connection); LogDebug("StartSubscription {4} {0}, {1}, {2}, {3}.", operation.GetType().Name, operation, msg.MaxRetries, msg.Timeout, _state == ConnectionState.Connected ? "fire" : "enqueue"); var subscription = new SubscriptionItem(operation, msg.MaxRetries, msg.Timeout); if (_state == ConnectionState.Connecting) { _subscriptions.EnqueueSubscription(subscription); } else { _subscriptions.StartSubscription(subscription, _connection); } break; case ConnectionState.Closed: msg.Source.SetException(new ObjectDisposedException(_esConnection.ConnectionName)); break; default: throw new Exception(string.Format("Unknown state: {0}.", _state)); } }
internal EventStoreSubscription(SubscriptionOperation subscriptionOperation, string streamId, long lastCommitPosition, int?lastEventNumber) { Ensure.NotNull(subscriptionOperation, "subscriptionOperation"); _subscriptionOperation = subscriptionOperation; _streamId = streamId; LastCommitPosition = lastCommitPosition; LastEventNumber = lastEventNumber; }
internal static void SubscribeEvents(string clientId, string topicName, NCache nCache, OperationContext operationContext) { SubscriptionInfo subInfo = new SubscriptionInfo() { SubscriptionId = SubscriptionInfo.EventsSubscriptionName, ClientId = clientId, Type = SubscriptionType.Subscriber, SubPolicyType = SubscriptionPolicyType.EventSubscription, Expiration = TimeSpan.MaxValue.Ticks }; var topicOperation = new SubscriptionOperation(topicName, TopicOperationType.Subscribe, subInfo); bool subscribed = nCache.Cache.TopicOpertion(topicOperation, operationContext); }
/// <summary> /// Update a subscription /// </summary> /// <param name="subscriptionId">The subscription id</param> /// <param name="planId">The plan id</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <FulfillmentManagerOperationResult> RequestUpdateSubscriptionAsync( Guid subscriptionId, string planId, CancellationToken cancellationToken = default) { try { _logger.LogInformation( LoggingUtils.ComposeHttpClientLogMessage( _fulfillmentClient.GetType().Name, nameof(_fulfillmentClient.UpdateSubscriptionAsync), subscriptionId)); Guid requestId = Guid.NewGuid(); Guid correlationId = Guid.NewGuid(); ActivatedSubscriptionResult activatedSubscription = new ActivatedSubscriptionResult { PlanId = planId }; UpdateOrDeleteSubscriptionRequestResult response = await _fulfillmentClient.UpdateSubscriptionAsync( subscriptionId, activatedSubscription, requestId, correlationId, cancellationToken); _logger.LogInformation( LoggingUtils.ComposeSubscriptionActionMessage( "Updated", subscriptionId, activatedSubscription.PlanId, activatedSubscription.Quantity)); SubscriptionOperation operation = await _fulfillmentClient.GetSubscriptionOperationAsync( subscriptionId, response.OperationId, requestId, correlationId, cancellationToken); FulfillmentManagerOperationResult returnResult = FulfillmentManagerOperationResult.Success; returnResult.Operation = operation; return(returnResult); } catch (Exception e) { var errorMessage = $"Cannot update subscription {subscriptionId}."; throw new LunaFulfillmentException(errorMessage, e); } }
public SubscriptionItem(SubscriptionOperation operation, int maxRetries, TimeSpan timeout) { Ensure.NotNull(operation, "operation"); Operation = operation; MaxRetries = maxRetries; Timeout = timeout; CreatedTime = DateTime.UtcNow; CorrelationId = Guid.NewGuid(); RetryCount = 0; LastUpdated = DateTime.UtcNow; }
public static bool IsBillingNotPaymentNotification(this SubscriptionOperation operation) => default;
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); int overload = 1; bool subscribed = false; string exceptionMessage = null; try { NCache nCache = clientManager.CmdExecuter as NCache; var operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); if (command.commandVersion < 1) { operationContext.Add(OperationContextFieldName.ClientLastViewId, forcedViewId); } else //NCache 4.1 SP1 or later { operationContext.Add(OperationContextFieldName.ClientLastViewId, command.clientLastViewId.ToString(CultureInfo.InvariantCulture)); } CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress); if (nCache != null) { _command = command.subscribeTopicCommand; SubscriptionInfo subscriptionInfo = new SubscriptionInfo() { SubscriptionId = _command.subscriptionName, ClientId = clientManager.ClientID, Type = (SubscriptionType)_command.pubSubType, SubPolicyType = (SubscriptionPolicyType)_command.subscriptionPolicy, CreationTime = _command.creationTime, Expiration = _command.expirationTime }; SubscriptionOperation subOperation = new SubscriptionOperation(_command.topicName, TopicOperationType.Subscribe, subscriptionInfo); subscribed = nCache.Cache.TopicOpertion(subOperation, operationContext); stopWatch.Stop(); //Common.Protobuf.Response response = new Common.Protobuf.Response(); Common.Protobuf.SubscribeTopicResponse subscribeTopicResponse = new Common.Protobuf.SubscribeTopicResponse(); subscribeTopicResponse.success = subscribed; if (clientManager.ClientVersion >= 5000) { Common.Util.ResponseHelper.SetResponse(subscribeTopicResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(subscribeTopicResponse, Common.Protobuf.Response.Type.SUBSCRIBE_TOPIC)); } else { //PROTOBUF:RESPONSE Common.Protobuf.Response response = new Common.Protobuf.Response(); response.subscribeTopicResponse = subscribeTopicResponse; Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.SUBSCRIBE_TOPIC); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } } catch (Exception exc) { exceptionMessage = exc.ToString(); _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.CreateTopicSubscriptoin); log.GenerateSubscribeToTopicAPILogItem(_command.topicName, (SubscriptionType)_command.pubSubType, executionTime, clientManager.ClientID, clientManager.ClientIP, overload, subscribed, exceptionMessage, APIClassNames.TOPIC); } } catch { } } }
public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command) { System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); int overload = 1; bool unSubscribed = false; string exceptionMessage = null; try { NCache nCache = clientManager.CmdExecuter as NCache; var operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); if (command.commandVersion < 1) { operationContext.Add(OperationContextFieldName.ClientLastViewId, forcedViewId); } else { operationContext.Add(OperationContextFieldName.ClientLastViewId, command.clientLastViewId.ToString(CultureInfo.InvariantCulture)); } if (nCache != null) { _command = command.unSubscribeTopicCommand; SubscriptionInfo subInfo = new SubscriptionInfo() { SubscriptionId = _command.recepientId, ClientId = clientManager.ClientID, Type = (SubscriptionType)_command.pubSubType }; var topicOperation = new SubscriptionOperation(_command.topicName, TopicOperationType.UnSubscribe, subInfo); unSubscribed = nCache.Cache.TopicOpertion(topicOperation, operationContext); Common.Protobuf.Response response = new Common.Protobuf.Response(); Common.Protobuf.UnSubscribeTopicResponse unSubscribeTopicResponse = new Common.Protobuf.UnSubscribeTopicResponse(); response.requestId = _command.requestId; response.commandID = command.commandID; unSubscribeTopicResponse.success = unSubscribed; response.responseType = Common.Protobuf.Response.Type.UNSUBSCRIBE_TOPIC; response.unSubscribeTopicResponse = unSubscribeTopicResponse; _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { exceptionMessage = exc.ToString(); _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.UnSubscribe); log.GenerateSubscribeToTopicAPILogItem(_command.topicName, (SubscriptionType)_command.pubSubType, executionTime, clientManager.ClientID, clientManager.ClientIP, overload, unSubscribed, exceptionMessage, APIClassNames.TOPICSUBSCRIPTION); } } catch { } } }