Click here to Skip to main content
15,887,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using RabbitMQ to get real time data. I make the connection and am getting data successfully. I am able to print it in the Debug line, but its not updating my Label.

here is my code:

C#
private void InitRabbit()
{

    factory.UserName = this.user;
    factory.Password = this.password;
    factory.HostName = this.host;
    factory.VirtualHost = "/";

    try
    {
        using (IConnection connection = factory.CreateConnection())
        {
            using (IModel channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(realTimeExchange, "topic");
                string queueName = channel.QueueDeclare();
                StringBuilder sb = new StringBuilder();
                sb.Append("QEH").Append(".").Append("QEH").Append(".*");
                channel.QueueBind(queueName, realTimeExchange, sb.ToString());
                Console.WriteLine("Waiting for messages");
                QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
                channel.BasicConsume(queueName, true, consumer);
                while (true)
                {
                    BasicDeliverEventArgs e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
                    Console.WriteLine(Encoding.ASCII.GetString(e.Body));
                    string msg = Encoding.ASCII.GetString(e.Body);
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    Alerts alert = ser.Deserialize<Alerts>(msg);
                    updatealert(alert); //for getting the Alerts which is my internal class
                }
            }
            rabbitrunning = true;
        }
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine("Rabbit not running : " + ex.Message);
    }
}

Here is my updatealert function:

ASP.NET
private void updatealert(Alerts alert)
{
    alertext.Text = "Count " + alert.CarName;
    System.Diagnostics.Debug.WriteLine("publish : " + alert.CarName);//its writting the message correctly but its not updating my Alertext label.
}
Here is the update panel structure:

<asp:ScriptManager ID="ScriptManager1"  runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
    <ContentTemplate>
        <legend>UpdatePanel</legend>
         <asp:Label ID="alertext" runat="server" Text="change" ></asp:Label>
         <asp:Label ID="Label1" runat="server" Text="change" ></asp:Label>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Get Real Data" />

How do I change the label text while rabbitMQ is updating the content?

UPDATES : After Long Trail and error I found that the rabbit is sending a lot of messages per second so the Update panel is not updating fast , so I tried to put the Update panel job in other thread but I have not succeeded , is there any advice how to update the panel with handling very fast process ?

Regards.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900