예제 #1
0
 /// <summary>
 /// Ctor with a publish endpoint, event writer and logger
 /// </summary>
 /// <param name="publishEndpoint"></param>
 /// <param name="ceWriter"></param>
 /// <param name="logger"></param>
 public BusinessService(IPublishEndpoint publishEndpoint, ICloudEventWriter ceWriter,
                        ILogger <BusinessService> logger)
 {
     this._publishEndpoint = publishEndpoint;
     this._ceWriter        = ceWriter;
     this._logger          = logger;
 }
예제 #2
0
 /// <summary>
 /// Publish a CloudEvent of type <see cref="IGenericEvent{TEvent}"/> with the specified payload and (optionally) event subject
 /// </summary>
 /// <typeparam name="TPayload"></typeparam>
 /// <typeparam name="TEvent"></typeparam>
 /// <param name="publishEndpoint"></param>
 /// <param name="writer"></param>
 /// <param name="payload"></param>
 /// <param name="eventSubject"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public static async Task PublishGenericCloudEvent <TPayload, TEvent>(this IPublishEndpoint publishEndpoint,
                                                                      ICloudEventWriter writer, TPayload payload, string eventSubject = null,
                                                                      CancellationToken cancellationToken = default(CancellationToken)) where TEvent : class, IEvent
 {
     await publishEndpoint.Publish <TEvent>(
         CloudEventProducer.GetEvent <TPayload, TEvent>(writer, payload, eventSubject),
         cancellationToken);
 }
예제 #3
0
        /// <summary>
        /// Adds the formatted payload to a CloudEvent envelope and returns an <see cref="IGenericEvent{TEvent}"/>
        /// with the serialized CloudEvent as event data
        /// </summary>
        /// <typeparam name="TPayload"></typeparam>
        /// <typeparam name="TEvent"></typeparam>
        /// <param name="writer"></param>
        /// <param name="payload"></param>
        /// <param name="eventSubject"></param>
        /// <returns></returns>
        public static IGenericEvent <TEvent> GetEvent <TPayload, TEvent>(ICloudEventWriter writer, TPayload payload, string eventSubject = null)
        {
            if (String.IsNullOrWhiteSpace(eventSubject))
            {
                eventSubject = String.Empty;
            }

            return(new GenericEventContract <TEvent>
            {
                EventData = writer.GetBytes <TPayload>(
                    payload, eventSubject: eventSubject)
            });
        }
예제 #4
0
        /// <summary>
        /// Adds the formatted payload to a CloudEvent envelope and returns an <see cref="IEvent"/>
        /// with the serialized CloudEvent as event data
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="writer"></param>
        /// <param name="payload"></param>
        /// <param name="eventSubject"></param>
        /// <returns></returns>
        public static IEvent GetEvent <T>(ICloudEventWriter writer, T payload, string eventSubject = null)
        {
            if (String.IsNullOrWhiteSpace(eventSubject))
            {
                eventSubject = String.Empty;
            }

            return(new EventContract
            {
                EventData = writer.GetBytes <T>(
                    payload, eventSubject: eventSubject)
            });
        }