重启后保留队列数据 [英] Persisting queue data after a restart

查看:183
本文介绍了重启后保留队列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要跟踪从第三方设备收到的字符串消息队列。重新启动应用程序后,我需要再次使用该队列。项目的入队和出列需要很快发生,因此性能是一个问题。



有关我应该使用的建议吗?



我的初步计划是使用文本文件模拟队列 - 每次将项目添加到队列时创建文件,并在项目出列时删除文件。然而,这似乎很笨拙,我不禁觉得必须有一个更好的方法来做到这一点。



我尝试了什么:



我最初刚开始使用System.Collections.Queue对象来存储消息,但我需要一种方法让队列在应用程序中可用重新启动。

I need to keep track of a queue of string messages that I receive from a third party device. I need that queue to be available again after the application is restarted. The enqueuing and dequeuing of items needs to happen pretty quickly, so performance is an issue.

Any advice of what I should be using?

My initial plan was to simulate a queue using text files - creating a file each time an item is added to the queue, and deleting a file when an item is dequeued. This however seems clunky, and I can't help but feel that there has to be a better way of doing this.

What I have tried:

I originally just started using the System.Collections.Queue object to store the messages, but I need a way for the queue to be available if the application is restarted.

推荐答案

使用数据库:INSERT到达时,在处理时删除。如果添加时间戳列,则可以轻松检索最旧的项目 - 即队列的头部。
Use a database: INSERT when they arrive, DELETE when they are processed. If you add a timestamp column, you can easily retrieve the oldest item - which is the head of the queue.


这篇关于重启后保留队列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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