qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SanathPrudhvi <Sanath_Prud...@mahindrasatyam.com>
Subject Re: Failed to connect
Date Mon, 14 Feb 2011 10:27:16 GMT

Dear Ted,

          When I run my application on same machine it is working fine.
But when I run the code on other machine, I got "Specified Module Could not
be found"
error. I am using VS 2008 with XP SP3 on both machines. apache qpid version
is 0.8.


          I am send the code for your reference. ( This is a window
application).
In this below code "cmbEvent_SelectedIndexChanged" function, when I tried to 
create the object, it is showing the specified error.

using System;
using Org.Apache.Qpid.Messaging;
using System.Text;
using System.Collections;
using System.Threading;
using CommonInterface;
using POCReports;

namespace AMQPPOC
{
    public class AMQP : IMessageQueuing
    {

        #region Private Members

        Connection connection = null;
        Session session = null;
        Sender sender = null;
        Receiver receiver = null;
        Message message = null;
        Address address = null;


        bool flag = true;
        string serverName = null;
        string portNumber = null;
        string requestQueue = null;
        string responseQueue = null;
        string userName = null;
        string password = null;

        StringBuilder sbMessages = null;

        #endregion

        #region Constructor

        public AMQP()
        {
            // set the default selected test as "Message Throughput"
            //SelectedTest = TestType.MessageThroughput;
        }

        #endregion

        #region IMessageQueuing Members

        public TestType SelectedTest
        {
            get;
            set;
        }

        public ReceivedMessageDetails ReceivedDetails
        {
            get;
            set;
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public void GetConfigurationDetails(Hashtable htConfigDetails)
        {

            if (htConfigDetails != null)
            {

                serverName = htConfigDetails["server"].ToString();
                portNumber = htConfigDetails["port"].ToString();
                requestQueue = htConfigDetails["request"].ToString();
                responseQueue = htConfigDetails["response"].ToString();
                userName = htConfigDetails["username"].ToString();
                password = htConfigDetails["password"].ToString();
            }

        }

        protected void cmbEvent_SelectedIndexChanged(object sender,
EventArgs e)
        {
                     AMQP q = new AMQP();
        }

        protected void start_click(object sender, EventArgs e)
        {
                StartService();
         }

        /// <summary>
        /// 
        /// </summary>
        public void StartService()
        {

            try
            {
                //start services / Brokers that are related to the event
mechanism
                connection = new Connection(serverName + ":" + portNumber);
                connection.Open();

                // create session for AMQP
                session = connection.CreateSession();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("AMQP Code \r\n" +
ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void StopService()
        {

            try
            {
                if (connection != null && session != null)
                {
                    // close session and connection..
                    if (sender != null)
                    {
                        sender.Close();
                        sender.Dispose();
                    }

                    if (receiver != null)
                    {
                        receiver.Close();
                        receiver.Dispose();
                    }

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public void SetServerConfiguration()
        {

            string sbReceivedMessages = null;
            sbMessages = new StringBuilder();

            try
            {
                // create receiver ...
                if (receiver == null)
                {
                    // if selected test is for priority test
                    if (SelectedTest == TestType.MessagePriorityLatency)
                        receiver = session.CreateReceiver(requestQueue +
                            "; {create:always,
node:{x-declare:{arguments:{x-qpid-priorities:10,qpid-fairshare:5}}}}");
                    else
                        receiver = session.CreateReceiver(requestQueue +
                            "; {create:always}");
                }

                // create sender incase of request / response type...
                Message responseMessage = new Message();
                int count = 1;
                int totalMessages = 1;

                while (flag)
                {

                    // display received message in text box..
                    try
                    {
                        // wait for unlimited time to receive a message
                        message = receiver.Fetch();

                        if ((SelectedTest == TestType.MessageThroughput) ||
                            (SelectedTest == TestType.RPCThroughput))
                        {
                            if (count == totalMessages)
                            {
                                sbReceivedMessages = String.Format(
                                    "{0: hh:mm:ss.fff}, {1} ", DateTime.Now,
                                    message.Subject);
                                ReceivedDetails(sbReceivedMessages);

                                totalMessages = int.Parse(message.UserId);
                            }

                            // if test type is RPC, give response to each
request
                            if (SelectedTest == TestType.RPCThroughput)
                            {
                                if ((address == null) ||
                                    (message.ReplyTo.Name != address.Name))
                                {
                                    address = message.ReplyTo;
                                    sender = session.CreateSender(address);
                                }

                                if (address != null)
                                {
                                   
responseMessage.SetContent(String.Format(
                                        "Response , {0}",
                                        message.GetContent()));
                                    responseMessage.Subject =
message.Subject;

                                    sender.Send(responseMessage, false);

                                    // record the sent/response time..
                                    if (count == 1 || count ==
totalMessages)
                                    {
                                       
frmReports.sbMessageReports.AppendLine(
                                            String.Format("{0 :
hh:mm:ss.fff} {1} , {2}",
                                            DateTime.Now, " Response ",
                                            message.Subject));
                                    }
                                    session.Acknowledge();
                                }
                            }
                        }

                        // display each message latency ...
                        if ((SelectedTest == TestType.MessageLatency) ||
                            (SelectedTest ==
TestType.MessagePriorityLatency))
                        {

                            if (count == 1)
                                totalMessages = int.Parse(message.UserId);

                            sbMessages.AppendLine(String.Format(
                            "{0: hh:mm:ss.fff} , {1} ", DateTime.Now,
                            message.Subject));

                            if (SelectedTest ==
TestType.MessagePriorityLatency)
                            {

                                address = message.ReplyTo;
                                sender = session.CreateSender(address);

                                // send the high priority message with same
priority
                                Message msgResponse = new Message();
                                msgResponse.SetContent((String.Format("{0}",
                                    message.GetContent())));
                                msgResponse.Subject = message.Subject;

                                if (message.Priority == 9)
                                    msgResponse.Priority = 9;

                                sender.Send(msgResponse);

                                frmReports.sbMessageReports.AppendLine(
                                    String.Format("{0 : hh:mm:ss.fff}, {1},
{2}",
                                    DateTime.Now, " Response ",
message.Subject));
                            }

                            if (count >= totalMessages)
                                ReceivedDetails(sbMessages.ToString());

                        }

                        ++count;
                        if (count > totalMessages)
                        {
                            flag = false;
                            System.Windows.Forms.MessageBox.Show("No
Messages to fetch");
                        }
                    }
                    catch (Exception ex)
                    {
                        flag = false;
                        throw ex;
                    }
                }
                frmReports.sbMessageReports.Insert(0, "Response Sent\r\n");
            }
            catch (Exception qex2)
            {
                System.Windows.Forms.MessageBox.Show(qex2.Message);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void SetClientConfiguration()
        {

            try
            {
                // create sender queue .. to send the addresses
                sender = session.CreateSender(requestQueue);

                // set request message...
                message = new Org.Apache.Qpid.Messaging.Message();
                Address response = null;

                // if selected test type is request / response
                if ((SelectedTest == TestType.RPCThroughput) ||
                    (SelectedTest == TestType.MessagePriorityLatency))
                {

                    if (SelectedTest == TestType.MessagePriorityLatency)
                    {
                        // create queue to receive response messages from
server...
                        response = new Address("#" + responseQueue +
                            "; {create:always, delete:always,
node:{x-declare:{arguments:{x-qpid-priorities:10,qpid-fairshare:5}}}}");
                    }
                    else
                    {
                        // create queue to receive response messages from
server...
                        response = new Address("#" + responseQueue +
                            "; {create:always, delete:always}");
                    }
                    // create receiver queue..
                    receiver = session.CreateReceiver(response);
                    message.ReplyTo = response;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// 
        /// 
        /// 
        public void SendRequest(string request, int messageCount,
            long messageSize, int highPriorityPosition)
        {

            try
            {

                if ((SelectedTest == TestType.RPCThroughput) ||
                    (SelectedTest == TestType.MessagePriorityLatency))
                {

                    Thread t = new Thread(
                        new
ParameterizedThreadStart(ReceiveReponseMessages));
                    t.Start(messageCount);
                }

                sender.Capacity = 50000;
                message.UserId = messageCount.ToString();
                int position = highPriorityPosition;

                for (int i = 1; i <= messageCount; i++)
                {

                    message.SetContent(request + " " + i.ToString());
                    message.Subject = i.ToString();

                    // set default message priority...
                    message.Priority = 5;

                    if ((SelectedTest == TestType.MessagePriorityLatency) &&
                        (i == position))
                    {
                        message.Priority = 9;
                        position = highPriorityPosition + position;
                    }

                    sender.Send(message, false);


                    if ((SelectedTest == TestType.MessageLatency) ||
                        (SelectedTest == TestType.MessagePriorityLatency))
                    {
                        frmReports.sbMessageReports.AppendLine(String.Format
                        ("{0 : hh:mm:ss.fff}, {1}, {3}, {2}", DateTime.Now,
" request ",
                        message.Priority, i));
                    }

                    if ((SelectedTest == TestType.RPCThroughput) ||
                        (SelectedTest == TestType.MessageThroughput))
                    {
                        if (i == 1 || i == messageCount)
                        {
                           
frmReports.sbMessageReports.AppendLine(String.Format
                            ("{0 : hh:mm:ss.fff}, {1}, {3} , {2}",
DateTime.Now, " request ",
                            message.Priority, i));
                        }
                    }

                    // send acknowledgement to client upon reaching the
destination
                    session.Acknowledge();
                }
                frmReports.sbMessageReports.Insert(0, "Request Sent \r\n");

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        // if user selects Request/Resposnse or Message Priority Latency
tests
        // wait for response messages from server
        private void ReceiveReponseMessages(object totalMessages)
        {

            // wait for server response, incase selected test is
request/response
            StringBuilder sbResponse = new StringBuilder();
            int count = 1;
            int messageCount = (int)totalMessages;

            while (flag)
            {

                try
                {
                    Message response = receiver.Fetch();

                    if ((SelectedTest == TestType.MessageThroughput) ||
                        (SelectedTest == TestType.RPCThroughput))
                    {

                        if (count == 1 || count == messageCount)
                        {
                            sbResponse.AppendLine(String.Format(
                                "{0: hh:mm:ss.fff}, {1}, {2}", DateTime.Now,
" Response ",
                                response.Subject));

                        }
                    }

                    if ((SelectedTest == TestType.MessageLatency) ||
                        (SelectedTest == TestType.MessagePriorityLatency))
                    {

                        sbResponse.AppendLine(String.Format(
                                "{0: hh:mm:ss.fff}, {1}, {2}", DateTime.Now,
" Response ",
                                response.Subject));
                    }

                    if (count >= messageCount)
                    {
                        ReceivedDetails(sbResponse.ToString());
                        sbResponse.Remove(0, sbResponse.Length);
                    }

                }
                catch (Exception ex)
                {
                    flag = false;
                    throw ex;
                }

                ++count;

                if (count > messageCount)
                {
                    flag = false;
                    System.Windows.Forms.MessageBox.Show("No Messages to
fetch");
                }
            }

        }

        #endregion
    }
}

thanks,
-Sanath

-- 
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Failed-to-connect-tp5999408p6023122.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Mime
View raw message