public void EnqueueDirectlyTo(string queue, string subqueue, MessagePayload payload) { EnsureEnslistment(); queueStorage.Global(actions => { var queueActions = actions.GetQueue(queue); var bookmark = queueActions.Enqueue(new PersistentMessage { Data = payload.Data, Headers = payload.Headers, Id = new MessageId { SourceInstanceId = queueStorage.Id, MessageIdentifier = GuidCombGenerator.Generate() }, Queue = queue, SentAt = DateTime.Now, SubQueue = subqueue, Status = MessageStatus.EnqueueWait }); actions.RegisterUpdateToReverse(Enlistment.Id, bookmark, MessageStatus.EnqueueWait, subqueue); actions.Commit(); }); lock (newMessageArrivedLock) { Monitor.PulseAll(newMessageArrivedLock); } }
public void EnqueueDirectlyTo(ITransaction transaction, string queue, string subqueue, MessagePayload payload, MessageId id = null) { var message = new PersistentMessage { Data = payload.Data, Headers = payload.Headers, Id = id ?? new MessageId { SourceInstanceId = _queueStorage.Id, MessageIdentifier = GuidCombGenerator.Generate() }, Queue = queue, SentAt = DateTime.Now, SubQueue = subqueue, Status = MessageStatus.EnqueueWait }; _queueStorage.Global(actions => { var queueActions = actions.GetQueue(queue); var bookmark = queueActions.Enqueue(message); actions.RegisterUpdateToReverse(transaction.Id, bookmark, MessageStatus.EnqueueWait, subqueue); }); _logger.QueuedForReceive(message); lock (_newMessageArrivedLock) { Monitor.PulseAll(_newMessageArrivedLock); } }
protected override void Seed(AdminContext context) { if (context.TenantMappings.FirstOrDefault() != null) { return; } var mappings = new List <TenantMapping>(); if (_debug) { context.TenantMappings.AddRange(DataFileLoader.Load <TenantMapping>("tenantmappings.json")); context.WsFedMappings.AddRange(DataFileLoader.Load <WsFedMapping>("wsfedmappings.json")); context.WsFedProtocolMappings.AddRange(DataFileLoader.Load <WsFedProtocolMapping>("wsfedprotocolmappings.json")); } else { context.TenantMappings.Add( new TenantMapping { TenantMappingId = GuidCombGenerator.Generate(), TenantId = AppSettings.AdminDomain, TenantName = AppSettings.IamClientName, ClientId = AppSettings.IamClientId }); } context.SaveChanges(); }
public Guid RegisterToSend(Endpoint destination, string queue, string subQueue, MessagePayload payload, Guid transactionId) { var bookmark = new MessageBookmark(); var msgId = GuidCombGenerator.Generate(); using (var update = new Update(session, outgoing, JET_prep.Insert)) { Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["msg_id"], msgId.ToByteArray()); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["tx_id"], transactionId.ToByteArray()); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["address"], destination.Host, Encoding.Unicode); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["port"], destination.Port); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["time_to_send"], DateTime.Now.ToOADate()); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["sent_at"], DateTime.Now.ToOADate()); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["send_status"], (int)OutgoingMessageStatus.NotReady); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["queue"], queue, Encoding.Unicode); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["subqueue"], subQueue, Encoding.Unicode); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["headers"], payload.Headers.ToQueryString(), Encoding.Unicode); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["data"], payload.Data); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["number_of_retries"], 1); Api.SetColumn(session, outgoing, ColumnsInformation.OutgoingColumns["size_of_data"], payload.Data.Length); update.Save(bookmark.Bookmark, bookmark.Size, out bookmark.Size); } Api.JetGotoBookmark(session, outgoing, bookmark.Bookmark, bookmark.Size); logger.DebugFormat("Created output message '{0}' for 'rhino.queues://{1}:{2}/{3}/{4}' as NotReady", msgId, destination.Host, destination.Port, queue, subQueue ); return(msgId); }
public static MessageId GenerateRandom() { return(new MessageId { SourceInstanceId = Guid.NewGuid(), MessageIdentifier = GuidCombGenerator.Generate() }); }
public object[] GatherConsumers(CurrentMessageInformation msg) { var message = msg.Message; object[] sagas = GetSagasFor(message); var sagaMessage = message as ISagaMessage; var msgType = message.GetType(); object[] instanceConsumers = subscriptionStorage .GetInstanceSubscriptions(msgType); var consumerTypes = reflection.GetGenericTypesOfWithBaseTypes(typeof(ConsumerOf <>), message); var occasionalConsumerTypes = reflection.GetGenericTypesOfWithBaseTypes(typeof(OccasionalConsumerOf <>), message); var consumers = GetAllNonOccasionalConsumers(consumerTypes, occasionalConsumerTypes, sagas); for (var i = 0; i < consumers.Length; i++) { var saga = consumers[i] as IAccessibleSaga; if (saga == null) { continue; } // if there is an existing saga, we skip the new one var type = saga.GetType(); if (sagas.Any(type.IsInstanceOfType)) { serviceLocator.Release(consumers[i]); consumers[i] = null; continue; } // we do not create new sagas if the saga is not initiated by // the message var initiatedBy = reflection.GetGenericTypeOf(typeof(InitiatedBy <>), msgType); if (initiatedBy.IsInstanceOfType(saga) == false) { serviceLocator.Release(consumers[i]); consumers[i] = null; continue; } saga.Id = sagaMessage != null ? sagaMessage.CorrelationId : GuidCombGenerator.Generate(); } return(instanceConsumers .Union(sagas) .Union(consumers.Where(x => x != null)) .ToArray()); }
/// <summary> /// Generate a new identifier /// </summary> /// <param name="session">The <see cref="T:NHibernate.Engine.ISessionImplementor" /> this id is being generated in.</param> /// <param name="obj">The entity for which the id is being generated.</param> /// <returns> /// The new identifier. /// </returns> public object Generate(ISessionImplementor session, object obj) { try { var id = assignedGenerator.Generate(session, obj); if (id is Guid && (Guid)id != default(Guid)) { return(id); } } catch (IdentifierGenerationException) { } return(guidCombGenerator.Generate(session, obj)); }
public void Consume(NewOrder message) { Console.WriteLine("Cashier: got new order"); var correlationId = GuidCombGenerator.Generate(); bus.Publish(new PrepareDrink { CorrelationId = correlationId, CustomerName = message.CustomerName, DrinkName = message.DrinkName, Size = message.Size }); bus.Reply(new PaymentDue { CustomerName = message.CustomerName, StarbucksTransactionId = correlationId, Amount = ((int)message.Size) * 1.25m }); }
private static void SeedTestData(IamContext context) { if (context.Users.Any(f => f.UserName == context.CacheKey)) { return; } var manager = new IamUserManager(new IamUserStore(context)); manager.UserValidator = new UserValidator <IamUser>(manager) { AllowOnlyAlphanumericUserNames = false }; var admin = new IamUser { Id = GuidCombGenerator.Generate().ToString(), UserName = context.CacheKey, Email = $"{context.CacheKey}@{context.CacheKey}.com" }; manager.Create(admin, $"{ConvertToProper(context.CacheKey)}123#"); manager.AddClaim( admin.Id, new Claim(Constants.ClaimTypes.Role, "Administrator")); var user = new IamUser { Id = GuidCombGenerator.Generate().ToString(), UserName = $"{context.CacheKey}-user", Email = $"{context.CacheKey}-user@{context.CacheKey}.com" }; manager.Create(user, $"{ConvertToProper(context.CacheKey)}123#"); manager.AddClaim( user.Id, new Claim(Constants.ClaimTypes.Role, "User")); }
public Guid RegisterToSend(Endpoint destination, string queue, string subQueue, MessagePayload payload, Guid transactionId) { var msgId = GuidCombGenerator.Generate(); var bookmark = outgoing.Insert(() => { outgoing.ForColumnType <GuidColumn>().Set("msg_id", msgId); outgoing.ForColumnType <GuidColumn>().Set("tx_id", transactionId); outgoing.ForColumnType <StringColumn>().Set("address", destination.Host); outgoing.ForColumnType <IntColumn>().Set("port", destination.Port); outgoing.ForColumnType <DateTimeColumn>().Set("time_to_send", DateTime.Now); outgoing.ForColumnType <DateTimeColumn>().Set("sent_at", DateTime.Now); outgoing.ForColumnType <IntColumn>().Set("send_status", (int)OutgoingMessageStatus.NotReady); outgoing.ForColumnType <StringColumn>().Set("queue", queue); outgoing.ForColumnType <StringColumn>().Set("subqueue", subQueue); outgoing.ForColumnType <StringColumn>().Set("headers", payload.Headers.ToQueryString()); outgoing.ForColumnType <BytesColumn>().Set("data", payload.Data); outgoing.ForColumnType <IntColumn>().Set("number_of_retries", 1); outgoing.ForColumnType <IntColumn>().Set("size_of_data", payload.Data.Length); if (payload.DeliverBy.HasValue) { outgoing.ForColumnType <DateTimeColumn>().Set("deliver_by", payload.DeliverBy.Value); } if (payload.MaxAttempts.HasValue) { outgoing.ForColumnType <IntColumn>().Set("max_attempts", payload.MaxAttempts.Value); } }); outgoing.MoveTo(bookmark); logger.Debug("Created output message '{0}' for 'lq.tcp://{1}:{2}/{3}/{4}' as NotReady", msgId, destination.Host, destination.Port, queue, subQueue ); return(msgId); }
/// <summary> /// Persists the specified work flow. /// </summary> /// <param name="workFlow">The work flow.</param> public void Save(IStateMachineContext workFlow) { if (workFlow == null) { throw new ArgumentNullException("workFlow"); } bool isPersisted = workFlow.Id != Guid.Empty; if (isPersisted == false) { workFlow.Id = GuidCombGenerator.Generate(); } string domainContextType = null; object domainContextId = null; object domainContext = GetDomainContext(workFlow); string domainContextStatusProperty = string.Empty; if (workFlow.DomainContext is ReflectiveDomainContextWrapper) { domainContextStatusProperty = ((ReflectiveDomainContextWrapper)workFlow.DomainContext).StateProperty.Name; } if (domainContext != null && _domainContextRepository != null) { _domainContextRepository.Save(domainContext); domainContextType = _domainContextRepository.GetTypeDescription(domainContext); domainContextId = _domainContextRepository.GetId(domainContext); } IStateMachineState currentState = workFlow.CurrentState; IWorkflowEntity workflowEntity = isPersisted ? _workflowPersister.Load(workFlow.Id) : _workflowPersister.CreateEmptyWorkflowEntity(workFlow.Id); if (workflowEntity == null) { throw new Exception("The workflow persister returned a null object from the CreateEmptyWorkflowEntity call."); } workflowEntity.WorkflowId = workFlow.Id; workflowEntity.CurrentState = currentState != null ? currentState.StateName : string.Empty; workflowEntity.MachineConfiguration = Convert.ToString(workFlow.StateMachine.Tag); workflowEntity.DomainContextTypeDescription = domainContextType; workflowEntity.DomainContextId = domainContextId; workflowEntity.DomainContextStatusProperty = domainContextStatusProperty; if (isPersisted && workFlow.IsComplete) { _workflowPersister.Complete(workflowEntity); } else if (isPersisted) { _workflowPersister.Update(workflowEntity); } else { _workflowPersister.Save(workflowEntity); } }