コード例 #1
0
        /// <summary>
        /// Envía un mensaje para el procesamiento asíncrono a una cola de Tibco para
        /// el procesamiento de distribuciones XBRL
        /// </summary>
        /// <param name="idDocumentoInstancia">Identificador del documento de instancia a procesar</param>
        /// <param name="idVersion">Versión del documento de instancia a procesar</param>
        /// <returns>El resultado de la operación de envío a  la cola de TIBCO</returns>
        public ResultadoOperacionDto EnviarSolicitudProcesarXBRL(long idDocumentoInstancia, long idVersion, int reintento = 0)
        {
            var resultado = new ResultadoOperacionDto();

            LogUtil.Info("Enviando mensaje a la cola para procesamiento asíncrono de documento: " + idDocumentoInstancia + ", Version:" + idVersion);
            try
            {
                EmsTemplate.SendWithDelegate(ColaDestino,
                                             delegate(ISession session)
                {
                    MapMessage message = session.CreateMapMessage();
                    message.SetLong(DistribucionDocumentoConstants.PARAM_MENSAJE_ID_DOCUMENTO, idDocumentoInstancia);
                    message.SetLong(DistribucionDocumentoConstants.PARAM_MENSAJE_ID_VERSION, idVersion);
                    message.SetInt(DistribucionDocumentoConstants.PARAM_MENSAJE_REINTENTO, reintento);
                    return(message);
                });
                resultado.Resultado = true;
                LogUtil.Info("Mensaje enviado a la cola para procesamiento asíncrono de documento: " + idDocumentoInstancia + ", Version:" + idVersion);
            }
            catch (Exception ex) {
                LogUtil.Error("Ocurrió un error al enviar mensaje a la cola de mensajes: " + ColaDestino + ": \n\r" + ex.StackTrace);
                resultado.Resultado = false;
                resultado.Mensaje   = "Ocurrió un error al enviar mensaje a la cola de mensajes: " + ColaDestino + ": " + ex.Message;
                resultado.Excepcion = ex.StackTrace;
                LogUtil.Error(resultado);
            }
            return(resultado);
        }
コード例 #2
0
        public void ParticipatingTransactionWithCommit()
        {
            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            IConnection        connection        = (IConnection)mocks.CreateMock(typeof(IConnection));
            ISession           session           = (ISession)mocks.CreateMock(typeof(ISession));

            using (mocks.Ordered())
            {
                SetupCommitExpectations(connection, connectionFactory, session);
            }

            mocks.ReplayAll();


            EmsTransactionManager tm = new EmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            EmsTemplate           nt = new EmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.Execute(delegate(ITransactionStatus status)
            {
                nt.Execute(new AssertSessionCallback(session));
                return(null);
            });

            tm.Commit(ts);

            mocks.VerifyAll();
        }
コード例 #3
0
        private EmsTemplate CreateTemplate()
        {
            EmsTemplate template = new EmsTemplate();

            template.DestinationResolver = mockDestinationResolver;
            template.SessionTransacted   = UseTransactedTemplate;
            return(template);
        }
コード例 #4
0
 public void Send(TradeRequest tradeRequest)
 {
     EmsTemplate.ConvertAndSendWithDelegate(tradeRequest, delegate(Message message)
     {
         message.ReplyTo       = defaultReplyToQueue;
         message.CorrelationID = new Guid().ToString();
         return(message);
     });
 }
コード例 #5
0
 public void SendMarketData()
 {
     while (true)
     {
         IDictionary data = GenerateFakeMarketData();
         log.Info("Sending market data.");
         EmsTemplate.ConvertAndSend(data);
         log.Info("Sleeping " + sleepTimeInSeconds + " seconds before sending more market data.");
         Thread.Sleep(sleepTimeInSeconds);
     }
 }
コード例 #6
0
 public void Publish(string ticker, double price)
 {
     EmsTemplate.SendWithDelegate("APP.STOCK.MARKETDATA",
                                  delegate(ISession session)
     {
         MapMessage message = session.CreateMapMessage();
         message.SetString("TICKER", ticker);
         message.SetDouble("PRICE", price);
         message.Priority = 5;
         return(message);
     });
 }
コード例 #7
0
        public void PublishUsingDict(string ticker, double price)
        {
            IDictionary marketData = new Hashtable();

            marketData.Add("TICKER", ticker);
            marketData.Add("PRICE", price);
            EmsTemplate.ConvertAndSendWithDelegate("APP.STOCK.MARKETDATA", marketData,
                                                   delegate(Message message)
            {
                message.Priority      = 5;
                message.CorrelationID = new Guid().ToString();
                return(message);
            });
        }
コード例 #8
0
        public void TransactionSuspension()
        {
            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            IConnection        connection        = (IConnection)mocks.CreateMock(typeof(IConnection));
            ISession           session           = (ISession)mocks.CreateMock(typeof(ISession));
            ISession           session2          = (ISession)mocks.CreateMock(typeof(ISession));


            Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Twice();
            Expect.Call(connection.CreateSession(true, Session.SESSION_TRANSACTED)).Return(session).Repeat.Once();
            Expect.Call(connection.CreateSession(true, Session.SESSION_TRANSACTED)).Return(session2).Repeat.Once();

            session.Commit();
            LastCall.On(session).Repeat.Once();
            session2.Commit();
            LastCall.On(session2).Repeat.Once();

            session.Close();
            LastCall.On(session).Repeat.Once();
            session2.Close();
            LastCall.On(session2).Repeat.Once();

            connection.Close();
            LastCall.On(connection).Repeat.Twice();

            mocks.ReplayAll();

            EmsTransactionManager tm = new EmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            EmsTemplate           nt = new EmsTemplate(connectionFactory);


            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(delegate(ITransactionStatus status)
            {
                nt.Execute(new AssertNotSameSessionCallback(session));
                return(null);
            });

            nt.Execute(new AssertSessionCallback(session));

            tm.Commit(ts);

            mocks.VerifyAll();
        }
コード例 #9
0
        public void SessionCallback()
        {
            EmsTemplate template = CreateTemplate();

            template.ConnectionFactory = mockConnectionFactory;
            mockSession.Close();
            LastCall.On(mockSession).Repeat.Once();
            mockConnection.Close();
            LastCall.On(mockConnection).Repeat.Once();

            mocks.ReplayAll();

            template.Execute(delegate(ISession session)
            {
                bool b = session.Transacted;
                return(null);
            });
            mocks.VerifyAll();
        }
コード例 #10
0
        public void TransactionRollback()
        {
            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            IConnection        connection        = (IConnection)mocks.CreateMock(typeof(IConnection));
            ISession           session           = (ISession)mocks.CreateMock(typeof(ISession));

            SetupRollbackExpectations(connection, connectionFactory, session);

            mocks.ReplayAll();

            EmsTransactionManager tm = new EmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            EmsTemplate           nt = new EmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));
            tm.Rollback(ts);

            mocks.VerifyAll();
        }
コード例 #11
0
        public void SendAndAsyncReceive()
        {
            SimpleMessageListenerContainer container =
                (SimpleMessageListenerContainer)applicationContext["SimpleMessageListenerContainer"];
            SimpleMessageListener listener = applicationContext["SimpleMessageListener"] as SimpleMessageListener;

            Assert.IsNotNull(container);
            Assert.IsNotNull(listener);

            Admin admin = new Admin("tcp://localhost:7222", "admin", null);

            admin.PurgeQueue("test.queue");

            EmsTemplate emsTemplate = (EmsTemplate)applicationContext["MessageTemplate"] as EmsTemplate;

            Assert.IsNotNull(emsTemplate);

            Assert.AreEqual(0, listener.MessageCount);
            emsTemplate.ConvertAndSend("Hello World 1");

            int waitInMillis = 2000;

            Thread.Sleep(waitInMillis);
            Assert.AreEqual(1, listener.MessageCount);

            container.Stop();
            Console.WriteLine("container stopped.");
            emsTemplate.ConvertAndSend("Hello World 2");
            Thread.Sleep(waitInMillis);
            Assert.AreEqual(1, listener.MessageCount);

            container.Start();
            Console.WriteLine("container started.");
            Thread.Sleep(waitInMillis);
            Assert.AreEqual(2, listener.MessageCount);

            container.Shutdown();

            Thread.Sleep(waitInMillis);
        }
コード例 #12
0
        public void ParticipatingTransactionWithRollback()
        {
            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            IConnection        connection        = (IConnection)mocks.CreateMock(typeof(IConnection));
            ISession           session           = (ISession)mocks.CreateMock(typeof(ISession));

            using (mocks.Ordered())
            {
                SetupRollbackExpectations(connection, connectionFactory, session);
            }

            mocks.ReplayAll();

            EmsTransactionManager tm = new EmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            EmsTemplate           nt = new EmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.Execute(delegate(ITransactionStatus status)
            {
                nt.Execute(new AssertSessionCallback(session));
                status.SetRollbackOnly();
                return(null);
            });
            try
            {
                tm.Commit(ts);
                Assert.Fail("Should have thrown UnexpectedRollbackException");
            } catch (UnexpectedRollbackException)
            {
            }

            mocks.VerifyAll();
        }
コード例 #13
0
        public void SessionCallbackWithinSynchronizedTransaction()
        {
            SingleConnectionFactory scf      = new SingleConnectionFactory(mockConnectionFactory);
            EmsTemplate             template = CreateTemplate();

            template.ConnectionFactory = scf;

            mockConnection.Start();
            LastCall.On(mockConnection).Repeat.Times(2);
            Expect.Call(mockSession.Transacted).Return(UseTransactedSession).Repeat.Twice();

            if (UseTransactedTemplate)
            {
                mockSession.Commit();
                LastCall.On(mockSession).Repeat.Once();
            }

            mockSession.Close();
            LastCall.On(mockSession).Repeat.Once();
            mockConnection.Stop();
            LastCall.On(mockConnection).Repeat.Once();
            mockConnection.Close();
            LastCall.On(mockConnection).Repeat.Once();

            mocks.ReplayAll();


            TransactionSynchronizationManager.InitSynchronization();

            try
            {
                template.Execute(delegate(ISession session)
                {
                    bool b = session.Transacted;
                    return(null);
                });
                template.Execute(delegate(ISession session)
                {
                    bool b = session.Transacted;
                    return(null);
                });

                Assert.AreSame(mockSession, ConnectionFactoryUtils.GetTransactionalSession(scf, null, false));
                Assert.AreSame(mockSession,
                               ConnectionFactoryUtils.GetTransactionalSession(scf, scf.CreateConnection(), false));

                //In Java this test was doing 'double-duty' and testing TransactionAwareConnectionFactoryProxy, which has
                //not been implemented in .NET

                template.Execute(delegate(ISession session)
                {
                    bool b = session.Transacted;
                    return(null);
                });

                IList synchs = TransactionSynchronizationManager.Synchronizations;
                Assert.AreEqual(1, synchs.Count);
                ITransactionSynchronization synch = (ITransactionSynchronization)synchs[0];
                synch.BeforeCommit(false);
                synch.BeforeCompletion();
                synch.AfterCommit();
                synch.AfterCompletion(TransactionSynchronizationStatus.Unknown);
            }
            finally
            {
                TransactionSynchronizationManager.ClearSynchronization();
                //Assert.IsTrue(TransactionSynchronizationManager.ResourceDictionary.Count == 0);
                //Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
                scf.Dispose();
            }
            Assert.IsTrue(TransactionSynchronizationManager.ResourceDictionary.Count == 0);
            mocks.VerifyAll();
        }
コード例 #14
0
 public SimplePublisher()
 {
     emsTemplate = new EmsTemplate(new EmsConnectionFactory("tcp://localhost:7222"));
 }