RabbitMQ与Asp.net问题 [英] RabbitMQ with Asp.net problem

查看:236
本文介绍了RabbitMQ与Asp.net问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RabbitMQ来获取实时数据。我建立连接并成功获取数据。我可以在Debug行中打印它,但它没有更新我的Label。



这里是我的代码:



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:

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);
    }
}



这是我的updatealert功能:




Here is my updatealert function:

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.

推荐答案

这篇关于RabbitMQ与Asp.net问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆