public void ProducerCallbackWithIdAndTimestampDisabled() { NmsTemplate template = CreateTemplate(); template.ConnectionFactory = mockConnectionFactory; template.MessageIdEnabled = false; template.MessageTimestampEnabled = false; IMessageProducer mockProducer = A.Fake <IMessageProducer>(); A.CallTo(() => mockSession.CreateProducer(null)).Returns(mockProducer); A.CallTo(() => mockProducer.Priority).Returns(MsgPriority.Normal); template.Execute((session, producer) => { bool b = session.Transacted; MsgPriority priority = producer.Priority; return(null); }); AssertCloseProducerSessionConnection(mockProducer); A.CallToSet(() => mockProducer.DisableMessageID).WhenArgumentsMatch(x => x.Get <bool>(0) == true).MustHaveHappenedOnceExactly(); A.CallToSet(() => mockProducer.DisableMessageTimestamp).WhenArgumentsMatch(x => x.Get <bool>(0) == true).MustHaveHappenedOnceExactly(); }
static void Main(string[] args) { Tracer.Trace = new NLogAdapter(); var brokerUri = "failover:(amqp://127.0.0.1:5672,amqp://127.0.0.1:5673)" + "?failover.initialReconnectDelay=1000" + "&failover.reconnectDelay=1000" + "&failover.maxReconnectAttempts=10"; var connectionFactory = new NmsConnectionFactory(brokerUri); var simpleMessageListenerContainer = new SimpleMessageListenerContainer { ConnectionFactory = connectionFactory, DestinationName = DestinationName, MessageListener = new MessageListener() }; // start listener simpleMessageListenerContainer.AfterPropertiesSet(); var cachingConnectionFactory = new CachingConnectionFactory(connectionFactory); var nmsTemplate = new NmsTemplate(cachingConnectionFactory) { DefaultDestinationName = DestinationName, }; while (true) { Logger.Info("Enter your message."); var text = Console.ReadLine(); nmsTemplate.SendWithDelegate(session => session.CreateTextMessage(text)); } }
public static void Send(string message, string queue) { ConnectionFactory connectionFactory = new ConnectionFactory(URI); NmsTemplate template = new NmsTemplate(connectionFactory); template.ConvertAndSend(queue, message); }
public void ParticipatingTransactionWithCommit() { IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>(); IConnection connection = A.Fake <IConnection>(); ISession session = A.Fake <ISession>(); SetupCreateSession(connection, connectionFactory, session); NmsTransactionManager tm = new NmsTransactionManager(connectionFactory); ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition()); NmsTemplate nt = new NmsTemplate(connectionFactory); nt.Execute(new AssertSessionCallback(session)); TransactionTemplate tt = new TransactionTemplate(tm); tt.Execute(status => { nt.Execute(new AssertSessionCallback(session)); return(null); }); tm.Commit(ts); AssertCommitExpectations(connection, connectionFactory, session); }
public void ProducerCallback() { NmsTemplate template = CreateTemplate(); template.ConnectionFactory = mockConnectionFactory; IMessageProducer mockProducer = mocks.StrictMock <IMessageProducer>(); Expect.Call(mockSession.CreateProducer(null)).Return(mockProducer); Expect.Call(mockProducer.Priority).Return(MsgPriority.Normal); CloseProducerSessionConnection(mockProducer); mocks.ReplayAll(); MsgPriority priority = MsgPriority.Highest; template.Execute((session, producer) => { bool b = session.Transacted; priority = producer.Priority; return(null); }); Assert.AreEqual(priority, MsgPriority.Normal); mocks.VerifyAll(); }
public void TransactionSuspension() { IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>(); IConnection connection = A.Fake <IConnection>(); ISession session = A.Fake <ISession>(); ISession session2 = A.Fake <ISession>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection).Twice(); A.CallTo(() => connection.CreateSession(AcknowledgementMode.Transactional)) .Returns(session).Once() .Then.Returns(session2).Once(); NmsTransactionManager tm = new NmsTransactionManager(connectionFactory); ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition()); NmsTemplate nt = new NmsTemplate(connectionFactory); TransactionTemplate tt = new TransactionTemplate(tm); tt.PropagationBehavior = TransactionPropagation.RequiresNew; tt.Execute(status => { nt.Execute(new AssertNotSameSessionCallback(session)); return(null); }); nt.Execute(new AssertSessionCallback(session)); tm.Commit(ts); A.CallTo(() => session.Commit()).MustHaveHappenedOnceExactly(); A.CallTo(() => session2.Commit()).MustHaveHappenedOnceExactly(); A.CallTo(() => session.Close()).MustHaveHappenedOnceExactly(); A.CallTo(() => session2.Close()).MustHaveHappenedOnceExactly(); A.CallTo(() => connection.Close()).MustHaveHappenedTwiceExactly(); }
public void ProducerCallbackWithIdAndTimestampDisabled() { NmsTemplate template = CreateTemplate(); template.ConnectionFactory = mockConnectionFactory; template.MessageIdEnabled = false; template.MessageTimestampEnabled = false; IMessageProducer mockProducer = mocks.StrictMock <IMessageProducer>(); Expect.Call(mockSession.CreateProducer(null)).Return(mockProducer); mockProducer.DisableMessageID = true; LastCall.On(mockProducer).Repeat.Once(); mockProducer.DisableMessageTimestamp = true; LastCall.On(mockProducer).Repeat.Once(); Expect.Call(mockProducer.Priority).Return(MsgPriority.Normal); CloseProducerSessionConnection(mockProducer); mocks.ReplayAll(); template.Execute((session, producer) => { bool b = session.Transacted; MsgPriority priority = producer.Priority; return(null); }); mocks.VerifyAll(); }
public void ParticipatingTransactionWithRollback() { IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>(); IConnection connection = A.Fake <IConnection>(); ISession session = A.Fake <ISession>(); SetupCreateSession(connection, connectionFactory, session); NmsTransactionManager tm = new NmsTransactionManager(connectionFactory); ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition()); NmsTemplate nt = new NmsTemplate(connectionFactory); nt.Execute(new AssertSessionCallback(session)); TransactionTemplate tt = new TransactionTemplate(tm); tt.Execute(status => { nt.Execute(new AssertSessionCallback(session)); status.SetRollbackOnly(); return(null); }); try { tm.Commit(ts); Assert.Fail("Should have thrown UnexpectedRollbackException"); } catch (UnexpectedRollbackException) { } AssertRollbackExpectations(connection, connectionFactory, session); }
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(); NmsTransactionManager tm = new NmsTransactionManager(connectionFactory); ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition()); NmsTemplate nt = new NmsTemplate(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(); }
public void HandleMessage(IMessage message) { if (message == null) { throw new ArgumentException("message must not be null"); } NmsTemplate.ConvertAndSend(message); }
private NmsTemplate CreateTemplate() { NmsTemplate template = new NmsTemplate(); template.DestinationResolver = mockDestinationResolver; template.SessionTransacted = UseTransactedTemplate; return(template); }
public void Send(TradeRequest tradeRequest) { NmsTemplate.ConvertAndSendWithDelegate(tradeRequest, delegate(IMessage message) { message.NMSReplyTo = defaultReplyToQueue; message.NMSCorrelationID = new Guid().ToString(); return(message); }); }
protected override void ConfigureMessageConverter(NmsTemplate nmsTemplate, INmsHeaderMapper headerMapper) { IMessageConverter converter = nmsTemplate.MessageConverter; if (converter == null || !(converter is HeaderMappingMessageConverter)) { HeaderMappingMessageConverter hmmc = new HeaderMappingMessageConverter(converter, headerMapper); hmmc.ExtractIntegrationMessagePayload = extractPayload; nmsTemplate.MessageConverter = hmmc; } }
/// <summary> /// Sends message to update the job status. /// </summary> /// <param name="ticketId">The ticket identifier.</param> /// <param name="jobStatus">The job status.</param> public void UpdateJobStatus(string ticketId, TicketStatus jobStatus) { NmsTemplate.SendWithDelegate(JobInfoDestination, delegate(ISession session) { var msg = session.CreateMessage(); msg.Properties.SetString(MessageKeys.TicketMessageKey, ticketId); msg.Properties.SetInt(MessageKeys.JobStatusMessageKey, (int)jobStatus); return(msg); }); }
public void SendMarketData() { while (true) { IDictionary data = GenerateFakeMarketData(); log.Info("Sending market data."); NmsTemplate.ConvertAndSend(data); log.Info("Sleeping " + sleepTimeInSeconds + " seconds before sending more market data."); Thread.Sleep(sleepTimeInSeconds); } }
/// <summary> /// Send log message to message queue. /// </summary> protected override void Append(LoggingEvent loggingEvent) { string text = RenderLoggingEvent(loggingEvent); string message = text.Replace("(null)", ""); if (!MessageValidation(message)) { return; } bool QueueFailureCountThresholdReached = (QueueFailureCount >= m_QueueFailureCountThreshold); bool QueueRestoreTimeThresholdReached; if (!QueueFailureCountThresholdReached) { QueueRestoreTimeThresholdReached = false; } else { TimeSpan t = System.DateTime.Now - LastQueueFailureTime; QueueRestoreTimeThresholdReached = t.TotalSeconds > m_QueueRestoreTimeThreshold; } if (!QueueFailureCountThresholdReached || QueueRestoreTimeThresholdReached) { if (QueueRestoreTimeThresholdReached) { // Queue Restore Time Threshold is reached. // It's time to clear the failure count and direct message to queue. QueueFailureCount = 0; log.Debug("Queue Restore Time Threshold (" + m_QueueRestoreTimeThreshold.ToString() + ") reached. Message is directed to queue."); } try { ConnectionFactory connectionFactory = new ConnectionFactory(m_QueueURI); NmsTemplate template = new NmsTemplate(connectionFactory); template.ConvertAndSend(m_QueueName, message); QueueFailureCount = 0; } catch (Exception e) { log.Fatal("An error occurred while sending message to queue.", e); QueueHelper.RecordOriginalMessage(message); QueueFailureCount++; LastQueueFailureTime = DateTime.Now; } } else { log.Debug("Queue Failure Count Threshold (" + m_QueueFailureCountThreshold.ToString() + ") reached. Message is directed to local file. "); QueueHelper.RecordOriginalMessage(message); } }
public void send <MSG>(MSG message, string queueName, string url, bool toLog = true) { ConnectionFactory conFactory = new ConnectionFactory(url); NmsTemplate temp = new NmsTemplate(conFactory); temp.Send(queueName, new GenericMessageCreator <MSG>(message)); if (toLog) { writeToLog("Sended message to " + queueName); } }
public void Publish(string ticker, double price) { NmsTemplate.SendWithDelegate("APP.STOCK.MARKETDATA", delegate(ISession session) { IMapMessage message = session.CreateMapMessage(); message.Body.SetString("TICKER", ticker); message.Body.SetDouble("PRICE", price); message.NMSPriority = MsgPriority.Normal; return(message); }); }
static void Main(string[] args) { Email testModel = new Email(); testModel.Receiver = "*****@*****.**"; testModel.Text = "TEST TEST TEST"; testModel.Header = "Nagłówek"; ConnectionFactory conFactory = new ConnectionFactory(Config.Url); NmsTemplate temp = new NmsTemplate(conFactory); temp.Send(Config.QueueName, new MessageCreator(testModel)); }
public void writeToLog(string message, LogMessage.LogType type = LogMessage.LogType.INFO) { LogMessage msg = new LogMessage(); msg.Message = message; msg.MessageType = type; msg.ServiceName = serviceName; ConnectionFactory conFactory = new ConnectionFactory(Config.Url); NmsTemplate temp = new NmsTemplate(conFactory); temp.Send(Config.QueueName, new GenericMessageCreator <LogMessage>(msg)); }
/// <summary> /// Sends message to record the GameShare replay video. /// </summary> /// <param name="ticketId">The ticket identifier.</param> /// <param name="casino">The casino name.</param> /// <param name="gameTitle">The game title.</param> /// <param name="gamePlayedAt">The game played-at time (milliseconds since epoch)</param> /// <param name="videoBytes">game share video as a byte array</param> public void UploadVideo(string ticketId, string casino, string gameTitle, long gamePlayedAt, byte[] videoBytes) { NmsTemplate.SendWithDelegate(VideoUploadDestination, delegate(ISession session) { var msg = session.CreateBytesMessage(); msg.Properties.SetString(MessageKeys.TicketMessageKey, ticketId); msg.Properties.SetString(MessageKeys.CasinoNameMessageKey, casino); msg.Properties.SetString(MessageKeys.GameTitleMessageKey, gameTitle); msg.Properties.SetLong(MessageKeys.GamePlayTimeMessageKey, gamePlayedAt); msg.WriteBytes(videoBytes); return(msg); }); }
public IMessage Receive() { object receivedObject = NmsTemplate.ReceiveAndConvert(); if (receivedObject == null) { return(null); } if (receivedObject is IMessage) { return((IMessage)receivedObject); } return(new Spring.Integration.Message.Message(receivedObject)); }
public void PublishUsingDict(string ticker, double price) { IDictionary marketData = new Hashtable(); marketData.Add("TICKER", ticker); marketData.Add("PRICE", price); NmsTemplate.ConvertAndSendWithDelegate("APP.STOCK.MARKETDATA", marketData, delegate(IMessage message) { message.NMSPriority = MsgPriority.Normal; message.NMSCorrelationID = new Guid().ToString(); return(message); }); }
public void SessionCallback() { NmsTemplate template = CreateTemplate(); template.ConnectionFactory = mockConnectionFactory; template.Execute(session => { bool b = session.Transacted; return(null); }); A.CallTo(() => mockSession.Close()).MustHaveHappenedOnceExactly(); A.CallTo(() => mockConnection.Close()).MustHaveHappenedOnceExactly(); }
public void AppLogs() { ConnectionFactory connectionFactory = new ConnectionFactory(URI); NmsTemplate template = new NmsTemplate(connectionFactory); string eventLogName = "Application"; EventLog eventLog = new EventLog(); eventLog.Log = eventLogName; foreach (EventLogEntry log in eventLog.Entries) { template.ConvertAndSend(DESTINATION, log.Message); } }
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(AcknowledgementMode.Transactional)).Return(session).Repeat.Once(); Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).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(); NmsTransactionManager tm = new NmsTransactionManager(connectionFactory); ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition()); NmsTemplate nt = new NmsTemplate(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(); }
public void TransactionRollback() { IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>(); IConnection connection = A.Fake <IConnection>(); ISession session = A.Fake <ISession>(); SetupCreateSession(connection, connectionFactory, session); NmsTransactionManager tm = new NmsTransactionManager(connectionFactory); ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition()); NmsTemplate nt = new NmsTemplate(connectionFactory); nt.Execute(new AssertSessionCallback(session)); tm.Rollback(ts); AssertRollbackExpectations(connection, connectionFactory, session); }
public void SuspendedTransaction() { IConnectionFactory connectionFactory = mocks.StrictMock <IConnectionFactory>(); IConnection connection = mocks.StrictMock <IConnection>(); ISession session = mocks.StrictMock <ISession>(); ISession session2 = mocks.StrictMock <ISession>(); Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Twice(); Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session).Repeat.Once(); Expect.Call(connection.CreateSession(AcknowledgementMode.AutoAcknowledge)).Return(session2).Repeat.Once(); session.Commit(); LastCall.On(session).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(); NmsTransactionManager tm = new NmsTransactionManager(connectionFactory); ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition()); NmsTemplate nt = new NmsTemplate(connectionFactory); nt.Execute(new AssertSessionCallback(session)); TransactionTemplate tt = new TransactionTemplate(tm); tt.PropagationBehavior = TransactionPropagation.NotSupported; tt.Execute(status => { nt.Execute(new AssertNotSameSessionCallback(session)); return(null); }); nt.Execute(new AssertSessionCallback(session)); tm.Commit(ts); mocks.VerifyAll(); }
public void SessionCallback() { NmsTemplate template = CreateTemplate(); template.ConnectionFactory = mockConnectionFactory; mockSession.Close(); LastCall.On(mockSession).Repeat.Once(); mockConnection.Close(); LastCall.On(mockConnection).Repeat.Once(); mocks.ReplayAll(); template.Execute(session => { bool b = session.Transacted; return(null); }); mocks.VerifyAll(); }
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(); NmsTransactionManager tm = new NmsTransactionManager(connectionFactory); ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition()); NmsTemplate nt = new NmsTemplate(connectionFactory); nt.Execute(new AssertSessionCallback(session)); tm.Rollback(ts); mocks.VerifyAll(); }