Example #1
0
        /// <summary>
        /// Publish the message on the message bus, if appropriate mapping is found in the
        /// message mapping file
        /// </summary>
        /// <typeparam name="t"></typeparam>
        /// <param name="message"></param>
        /// <param name="senderApplication"></param>
        public Response SendMessage(t message, ApplicationInfo senderApplication, TimeSpan messageTTL = default(TimeSpan))
        {
            Logger.Debug(string.Format("{0} published a message on {1}. Message = {2}", senderApplication.ApplicationName, DateTime.Now, message.ToJSON()));
            Response defaultResonse = DefaultResponse();

            if (!SupportedMessages.GetInstance().IsTypeSupported(message.GetType()))
            {
                Logger.Debug("default response returned. response = " + defaultResonse.ToJSON());
                return(defaultResonse);
            }

            if (storeManager.SaveMessage <t>(new BusMessage <t>(senderApplication.ApplicationName, message, messageTTL)))
            {
                defaultResonse.Success      = true;
                defaultResonse.ErrorMessage = "Message published successfully";
                defaultResonse.ErrorCode    = 0;
            }
            else
            {
                defaultResonse.ErrorMessage = "Failed to publish message";
            }

            Logger.Debug(defaultResonse.ToJSON());
            return(defaultResonse);
        }
        public void TestInitialization()
        {
            StorageManager manager = StorageManager.GetStorageManager();

            manager.initQueues(SupportedMessages.GetInstance());

            Assert.IsTrue(true);
        }
Example #3
0
        public void TestAutoSupportedTypeCreated()
        {
            SupportedMessages supportedMessages = SupportedMessages.GetInstance();

            Assert.IsNotNull(supportedMessages);
            List <SupportedType> list = ConfigManager.LoadSupportedTypes();

            Assert.AreEqual(list.Count, supportedMessages.Count);
        }
Example #4
0
 private IMongoCollection <BusMessage <t> > GetMongoCollection <t>()
 {
     if (SupportedMessages.GetInstance().IsTypeSupported(typeof(t)))
     {
         string collectionName = DBUtil.GetCollectionName(typeof(t));
         return(MongoDB.GetCollection <BusMessage <t> >(collectionName));
     }
     else
     {
         return(null);
     }
 }
Example #5
0
        public void Subscribe(Subscriber <t> subscriber, ApplicationInfo listenerApplication)
        {
            if (subscriber.IsNull() || listenerApplication.IsNull())
            {
                throw new ArgumentNullException();
            }

            if (!SupportedMessages.GetInstance().IsTypeSupported(typeof(t)))
            {
                throw new ArgumentException("Type not supported by MessageBus");
            }

            /**Here assumption is that only subscriber will exist one app context for one type of message.
             * if double entry is tried that system will ignore the subscription attempt. It is the
             * responsiblity of the caller to ensure that double subscription doesnt happen
             */

            if (!this.subscribers.ContainsKey(typeof(t).FullName))
            {
                MessageMonitor <t> messageMonitors = new MessageMonitor <t>(subscriber, listenerApplication);
                this.subscribers.Add(typeof(t).FullName, messageMonitors);
            }
        }
Example #6
0
 /// <summary>
 /// Steps of initiation are
 /// 1- open DB Connection
 /// 2- Create all required collections, if not existing
 /// 3- Open cursor with active records
 /// </summary>
 private void Init()
 {
     Logger.Debug("Bus manager initialized");
     storeManager = MessageBus.DataBase.Mongo.StorageManager.GetStorageManager();
     storeManager.initQueues(SupportedMessages.GetInstance());
 }