activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "roger.allen" <roger.al...@networkcentricsupport.com>
Subject Apache NMS ImessageConsumer.ReceiveNoWait() not returning a message
Date Fri, 09 Jun 2017 16:53:36 GMT
Hi

I've written an .net CLR interface to MS SQL 2012 to receive messages. It
works just fine:

        [SqlFunction(
        DataAccess = DataAccessKind.Read,
        FillRowMethodName = "ReceiveFromAMQ_FillRow",
        TableDefinition = "MessageId int, Message xml")]
        public static IEnumerable ReceiveFromAMQ(string strHost, string
strQueue, string strUser, string strPass, int iMaxMessages)
        {
            Uri connecturi = new Uri(strHost);
            string strMess;
            int iMessageCount = 0;
            ArrayList MessageCollection = new ArrayList();

            IConnectionFactory factory = new
Apache.NMS.ActiveMQ.ConnectionFactory(connecturi);

            using (IConnection connection =
factory.CreateConnection(strUser, strPass))
            using (ISession session = connection.CreateSession())
            {
                IDestination destination =
SessionUtil.GetDestination(session, strQueue);

                using (IMessageConsumer consumer =
session.CreateConsumer(destination))
                {
                    // Start the connection so that messages will be
processed.
                    connection.Start();
                    while (iMaxMessages == 0 || iMessageCount <
iMaxMessages)
                    {
                        ITextMessage message = consumer.Receive() as
ITextMessage;

                        if (message != null)
                        {
                            MessageCollection.Add(new AMQMessage(
                                ++iMessageCount,
                                ConvertString2SqlXml(message.Text)));
                        }
                        else
                        {
                            iMaxMessages = -1;
                        }
                    }
                }
            }
            return MessageCollection;
        }

However, if I change Receive() to either ReceiveNoWait() or
Receive(TimeSpan.FromSeconds(5)) then a null is returned even if there are
messages there. Can someone explain what I am missing here?

Thanks
Roger



--
View this message in context: http://activemq.2283324.n4.nabble.com/Apache-NMS-ImessageConsumer-ReceiveNoWait-not-returning-a-message-tp4727286.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Mime
View raw message