Esempio n. 1
0
        /// <summary>
        /// Use data contract XML for subscription serialization.
        /// </summary>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public static MessageBusConfiguration WithDataContractSubscriptionSerializer(this MessageBusConfiguration cfg)
        {
            IDocumentSerializer serializer = new DataContractDocumentSerializer();

            Xyperico.Agres.MessageBus.MessageBusConfigurationExtensions.SetSubscriptionSerializer(cfg, serializer);
            return(cfg);
        }
Esempio n. 2
0
        public static void SetMessageSink(MessageBusConfiguration cfg, IMessageSink messageSink)
        {
            Condition.Requires(messageSink, "messageSink").IsNotNull();

            IMessageSink s;

            if (cfg.TryGet <IMessageSink>(MessageSink_SettingsKey, out s))
            {
                throw new InvalidOperationException(string.Format("Cannot set message sink twice. Existing sink is {0} - now got {1}.", s, messageSink));
            }

            cfg.Set(MessageSink_SettingsKey, messageSink);
            Logger.DebugFormat("Using message sink {0}", messageSink);
        }
Esempio n. 3
0
        public static void SetMessageSource(MessageBusConfiguration cfg, IMessageSource messageSource)
        {
            Condition.Requires(messageSource, "messageSource").IsNotNull();

            IMessageSource s;

            if (cfg.TryGet <IMessageSource>(MessageSource_SettingsKey, out s))
            {
                throw new InvalidOperationException(string.Format("Cannot set message source twice. Existing source is {0} - now got {1}.", s, messageSource));
            }

            cfg.Set(MessageSource_SettingsKey, messageSource);
            Logger.DebugFormat("Using message source {0}", messageSource);
        }
Esempio n. 4
0
        public static void SetSubscriptionSerializer(MessageBusConfiguration cfg, IDocumentSerializer serializer)
        {
            Condition.Requires(serializer, "serializer").IsNotNull();

            IDocumentSerializer s;

            if (cfg.TryGet <IDocumentSerializer>(SubscriptionSerializer_SettingsKey, out s))
            {
                throw new InvalidOperationException(string.Format("Cannot set message bus subscription serializer twice. Existing serializer is {0} - now got {1}.", s, serializer));
            }

            cfg.Set(SubscriptionSerializer_SettingsKey, serializer);
            Logger.DebugFormat("Using {0} as serializer for subscription registrations", serializer);
        }
Esempio n. 5
0
        /// <summary>
        /// No more configuration needed for message bus - now configure something else or start the bus.
        /// </summary>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public static BaseConfiguration Done(this MessageBusConfiguration cfg)
        {
            IObjectContainer      container = ObjectContainerConfigurationExtensions.GetObjectContainer(cfg);
            IDocumentStoreFactory subscriptionStoreFactory = GetSubscriptionStore(cfg);

            if (!container.HasComponent(typeof(IRouteManager)))
            {
                container.AddComponent <IRouteManager, RouteManager>();
            }
            IRouteManager routeManager = container.Resolve <IRouteManager>();

            ISubscriptionService subscriptionService = new SubscriptionService(subscriptionStoreFactory, routeManager);

            cfg.Set(SubscriptionService_SettingsKey, subscriptionService);
            container.RegisterInstance <ISubscriptionService>(subscriptionService);

            return(new BaseConfiguration(cfg));
        }
Esempio n. 6
0
        /// <summary>
        /// Use file based storage for subscriptions.
        /// </summary>
        /// <param name="cfg"></param>
        /// <param name="baseDir"></param>
        /// <returns></returns>
        public static MessageBusConfiguration WithFileSubscriptionStore(this MessageBusConfiguration cfg, string baseDir)
        {
            if (cfg.ContainsKey(SubscriptionStoreFactory_SettingsKey))
            {
                throw new InvalidOperationException("You should not configure subscription store for message bus twice.");
            }

            Logger.Debug("Using plain files for storing subscription registrations.");
            Condition.Requires(cfg, "cfg").IsNotNull();
            Condition.Requires(baseDir, "baseDir").IsNotNull();

            IDocumentSerializer   documentSerializer = GetSubscriptionSerializer(cfg);
            IDocumentStoreFactory docStoreFactory    = new FileDocumentStoreFactory(baseDir, documentSerializer);

            cfg.Set(SubscriptionStoreFactory_SettingsKey, docStoreFactory);

            return(cfg);
        }