문제

나는 내 손에 흥미로운 상황을 가지고 있습니다. 이제 몇 년 동안 우리는 로깅을 위해 사용하는 네트워크에서 IIS 상자에서 실행되는 WCF 서비스가있었습니다. 응용 프로그램은 BasichTtpBinding을 사용하여 로그 메시지를 보내고 데이터베이스에 로그인합니다. 다른 모든 응용 프로그램의 로깅의 대부분은 작업 당 몇 가지 로그인으로 제한됩니다. 최근 에이 로깅 서비스를 사용하려면 다른 응용 프로그램을 이식했습니다. 이 응용 프로그램은 로깅 서비스를 위해 다른 클라이언트 중 하나보다 적극적으로 더 적극적으로 로그됩니다. 그것은 코스 중에 10 만 개의 메시지를 기록 할 수있는 작업이 있습니다 (이것은 CSV 파일을 통해 100,000 개의 레코드를 가져 오기위한 것입니다).

이 실행을보다 효율적으로 수행하는 방법을 찾으려고하면 로그 요청 (요청 성능을 위해 별도의 스레드에서 이 전송되었습니다). 이 방법으로 로그가 기록되는 동안 응용 프로그램이 차단되지 않습니다. 나는 지역 기계 에서이 MSMQ 솔루션에 대한 개념 증명을 구현했지만 이전에 MSMQ를 사용한 적이 없었으므로 현재 기술적으로 그 장소가 무엇인지를 배우면서 나는 많은 질문과 몇 가지 답변을 가진 나 자신을 찾는 것입니다. ...에 나는 누군가가 MSMQ가 어떻게 작동하는지에 대한 몇 가지 간결한 정보를 가리킬 수 있기를 바랍니다. 그래서이 개념의 증거를 더 잘 알 수 있습니다.

MSMQ를 구현 한 후에 보는 것 :

  • 로그를 보내는 내 응용 프로그램 MSMQ는 거의 즉시 반환됩니다 (로그가 기다리지 않고 내가 원하는 것인가?
  • 가 1000 개의 로그를 보냈지만 MSMQ 응용 프로그램은 30 미만입니다 초, 몇 분이 걸립니다 모든 1000 개의 로그가 데이터 베이스. 마치 나의 것처럼 보입니다 대기열에는 일종의 스로틀이 있습니다 그를 누른 곳으로 사용 가능하게 로그 요청하지만 어떻게 확인할 수 있는지 / 어디에서 확인할 수 있습니다.
  • MSMQ 서비스의 로그를 수신하는 서버에서 Net.tcp를 사용하는 경우 로그의 서비스 시간 초과 오류를 얻고 로그의 90 % (정도)만이 데이터베이스로 만드는 것만이지만 BasichTtpBinding을 사용하면 작동합니다. 안정적으로.

    여기에 MSMQ 서비스의 코드가 있습니다.

    public void QueueLog(Log log)
    {
        try
        {
            ServiceClient writeLog = getLoggingService();
    
            string exceptionText = log.Exception == null ? string.Empty : log.Exception.ToString();
            writeLog.WriteCompatibleLog(log.LoggerName, (LoggingService.Logging.LogType)log.LogType, exceptionText, log.Message, log.ApplicationName, Utility.GetAssemblyVersion(Assembly.GetCallingAssembly()),
                Utility.GetFirstIPAddress(), Utility.GetHostName(), log.Category);
        }
        catch (Exception ex)
        {
            Debug.WriteLine("LoggingServiceWrapper.DotNet Error\n\n" + ex.GetBaseException().Message + "\n\n" + ex.GetBaseException().StackTrace);
        }
    }
    
    private ServiceClient getLoggingService()
    {
        return new ServiceClient(new BasicHttpBinding(), new EndpointAddress("http://MyServer/Service.svc"));
    
    }
    
    .

    여기에 MSMQ 서비스를 만드는 코드가 있습니다

    if (!MessageQueue.Exists(Properties.Settings.Default.QueueName))
    {
        MessageQueue.Create(Properties.Settings.Default.QueueName, true);
    }
    
    ServiceHost serviceHost = new ServiceHost(typeof(LoggingServiceQueue.LoggingServiceQueue), new Uri(Properties.Settings.Default.Address));
    {
        serviceHost.Open();
    
        Console.ReadLine();
    
        serviceHost.Close();
    }
    
    .

    여기에 MSMQ 서비스를 호출하는 데 사용하는 응용 프로그램의 코드입니다.

    LoggingServiceQueueClient client = new LoggingServiceQueueClient(new NetMsmqBinding(NetMsmqSecurityMode.None), new EndpointAddress("net.msmq://localhost/private/Logging"));
    
    client.QueueLog(new LoggingServiceQueue.Log
    {
        LoggerName = loggerName,
        LogType = (LoggingServiceQueue.LogType)logType,
        ApplicationName = applicationName,
        Category = category,
        Exception = exception,
        Message = message,
        SourceHostName = Utility.GetHostName(),
        SourceIp = Utility.GetFirstIPAddress(),
        Version = Utility.GetAssemblyVersion(callingAssembly)
    });
    
    .

    누군가가 제공 할 수있는 도움을 주셔서 감사합니다. 나는 MSMQ를 사용하여 어떤 기능을 사용할 수 있는지 정확히 어떤 기능을 사용할 수 있는지 정확히 잃어 버렸습니다. 나는 Google을 통해 6 시간 ~ 몇 시간의 연구를 해왔습니다. 내가 발견 한 대부분의 문서는 꽤 오래되었다 (2007 년)이며 힘든 읽기입니다. 아마도 그들은 내가 주제에 대한 지식의 몇 가지 지식을 기대하고 있습니다.

도움이 되었습니까?

해결책

What you're seeing (if you're using net.msmq binding on your WCF) is what is designed to happen.

MSMQ, as a store-and-forward facility, will store messages in a queue at the sending client and the receiving server until either network or processing bandwidth is available. What this does is take load off the client (as you've observed) by making the process asynchronous.

You can view the statuses of the queues using Performance Monitor, the number of messages in the outbound queue (at the client) and the server queue are written to performance counters in realtime and can be viewed and/or logged.

If the performance is sub-optimal, you could look to change the WCF throttling settings to allow more concurrent connections in your service behaviour.

e.g.

<serviceThrottling
         maxConcurrentCalls="20"
         maxConcurrentSessions="20"
         maxConcurrentInstances="20"
       />

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top