/// <summary> /// Publishes the messages to all subscribers of the first message's type. /// </summary> public virtual void Publish <T>(params T[] messages) { if (messages == null || messages.Length == 0) // Bus.Publish<IFoo>(); { Publish(CreateInstance <T>(m => { })); return; } MessagingBestPractices.AssertIsValidForPubSub(messages[0].GetType()); var fullTypes = GetFullTypes(messages as object[]); var eventMessage = new TransportMessage { MessageIntent = MessageIntentEnum.Publish }; MapTransportMessageFor(messages as object[], eventMessage); if (MessagePublisher == null) { throw new InvalidOperationException("No message publisher has been registered. If you're using a transport without native support for pub/sub please enable the message driven publishing feature by calling: Feature.Enable<MessageDrivenPublisher>() in your configuration"); } var subscribersExisted = MessagePublisher.Publish(eventMessage, fullTypes); if (!subscribersExisted && NoSubscribersForMessage != null) { NoSubscribersForMessage(this, new MessageEventArgs(messages[0])); } }
// Will get invoked, whenever a new event is published by the Msmq publishers // and when they notify the bridge. The bridge is a MSMQ and the publishers // have an entry for this queue in their subscription storage. public bool Handle(TransportMessage message) { var headers = message.Headers; Type[] eventTypes = { Type.GetType(headers["NServiceBus.EnclosedMessageTypes"]) }; var msmqId = headers["NServiceBus.MessageId"]; // Set the Id to a deterministic guid, as Sql message Ids are Guids and // Msmq message ids are guid\nnnn. Newer versions of NServiceBus already // return just a guid for the messageId. So, check to see if the Id is // a valid Guid and if not, only then create a valid Guid. This check // is important as it affects the retries if the message is rolled back. // If the Ids are different, then the recoverability won't know its the same message. Guid newGuid; if (!Guid.TryParse(msmqId, out newGuid)) { headers["NServiceBus.MessageId"] = GuidBuilder.BuildDeterministicGuid(msmqId).ToString(); } log.Info("Forwarding message to all the SQL subscribers via a Publish"); publisher.Publish(message, new PublishOptions(eventTypes.First())); return(true); }
// Will get invoked, whenever a new event is published by the Msmq publishers // and when they notify the bridge. The bridge is a MSMQ and the publishers // have an entry for this queue in their subscription storage. public bool Handle(TransportMessage msmqMessage) { var eventTypes = ExtractEventTypes(msmqMessage.Headers); var sqlMessage = TranslateToSqlTransportMessage(msmqMessage); log.Info("Forwarding message to all the SQL subscribers via a Publish"); publisher.Publish(sqlMessage, new PublishOptions(eventTypes.First())); return(true); }
public void Handle(PositionAcquired message) { _price10SecondWindow.Add(message.Price); _price13SecondWindow.Add(message.Price); UpdateStopLossPrice(); _publisher.Publish(new SendToMeIn { DelayInSeconds = 10, Inner = new RemoveFrom10SecondWindow { Price = message.Price } }); _publisher.Publish(new SendToMeIn { DelayInSeconds = 13, Inner = new RemoveFrom13SecondWindow { Price = message.Price } }); }
protected void PublishMessage(IPublishMessages publisher, Type eventType, int i) { publisher.Publish(GenerateTransportMessage(i, eventType.FullName), new[] { eventType }); }
public void Publish(TransportMessage message, PublishOptions publishOptions) { message.Headers[SessionCopInBehavior.Header] = sessionId; wrappedPublisher.Publish(message, publishOptions); }