6

我目前正在使用 SignalR 和 ASP.Net MVC 4 应用程序。我正在使用来自 RabbitMQ 的消息,并且本质上需要在有新消息进入队列时通过 SignalR 进行广播。问题是在正常使用情况下,IIS 中没有一个长期存在的对象可以存在的地方。我每秒收到大约 1000 条消息,因此通过从外部队列监视服务/应用程序发出请求将消息推送到 IIS 的标准方法几乎会杀死我的 IIS。

我有一个在后台线程上创建单例实例的一般想法。不确定在 iis 中执行此操作的最佳方法是什么,如果应用程序死亡,希望单例自动重新创建。

4

1 回答 1

1

Are you thinking you would have something in a background thread that would check for messages every so often?

I have used quartz.net to create scheduled jobs in the past. They are fairly simple to set up. You can basically just say, execute this job every x interval starting at y time. With whatever solution you go with you will probably need to add in error handling. I think your quartz job would keep trying to execute every x interval even if it threw an exception, but you will need to make sure that you clear out whatever caused the exception in the first place. Otherwise every time it runs it will fail. I.E. like if there is something wrong with your message such that it will error every time you try and broadcast it.

Watch out for IdleTimeout of your application. If IIS puts your web app to sleep your singleton in your background worker/quartz job goes to sleep too. If you set IdleTimeout to 0 your application will never sleep.

If you init your job/worker in Global.asax.cs Application_Start() your job will always start when your web app does.

When you first deploy your app or update it or restart it you will need to make sure your app is running. Not sure if there is a setting for this in IIS. But normally your application doesn't start up until a request is made to it. Good luck. Let me know if you find a solution to this.

Same deal if you app crashes for some other reason. You need something to re-start your web app.

Hope that helps!

于 2012-12-15T15:07:53.227 回答