Please clarify what you mean by server gets stuck.
You are not able to stop the server? Meaning that you ended in the endless foreach (...GetConsumingEnumerable())
loop?
- You need to call
server.Stop();
and messageQueue.CompleteAdding();
somewhere when you want to stop the server and finish the loop.
You are not able to process more messages from some point?
- I don't know what your
replil_syslog_messages.Add(messageModel)
and SaveChanges()
methods do, but if either of them throws an exception it will lead to exiting the foreach
loop = you will stop processing further messages. Here, I would suggest to place body of the loop in the try - catch
block.
- Also please make sure that none of those methods get stuck.
You are not able to process any message?
- Please make sure that
if (_entities.SaveChanges().Equals(1))
is passed, no exceptions are thrown and the execution continues to foreach (...GetConsumingEnumerable())
loop.
Or something else is happening? Are you getting some errors?
- Please consider to register the
server.ErrorOccurred
event as well and handle/log server errors as well.
In any case, it will be very useful if you turn on server logging and examine the log when the server gets stuck. It can be done like this:
var server = new SyslogServer();
server.LogWriter = new Rebex.FileLogWriter(@"c:\data\syslog.log", Rebex.LogLevel.Debug);
Also consider to register the server.MessageReceived
event before you call server.Start();
to prevent possible loss of early messages.