2016-09-28 1 views
0

게시자 확인을 C#에서 구현하려고하고 있으므로 다음 코드를 찾으려고합니다. 형식 또는 네임 스페이스 이름 'BasicAckEventHandler'를 찾을 수 없습니다 (사용 지시문 또는 어셈블리 참조가 누락 되었습니까?)

https://stackoverflow.com/a/18211367/3139595

_rabbitMqChannel.BasicAcks += new BasicAckEventHandler(_rabbitMqChannel_BasicAcks); 
_rabbitMqChannel.BasicNacks += new BasicNackEventHandler(_rabbitMqChannel_BasicNacks); 

_rabbitMqChannel.ExchangeDeclare(ExchangeName, ExchangeTypeVal.ToString()); 
_rabbitMqChannel.QueueDeclare(QueueName, QueueDurable, QueueExclusive, QueueDelete, null); 
_rabbitMqChannel.QueueBind(QueueName, ExchangeName, RoutingKey); 
and here is how the event handlers methods will look like... 

private void _rabbitMqChannel_BasicNacks(IModel model, BasicNackEventArgs args) 
{ 
    throw new NotImplementedException(); 
} 

private void _rabbitMqChannel_BasicAcks(IModel model, BasicAckEventArgs args) 
{ 
    throw new NotImplementedException(); 
} 

이 대답은 그를 위해 일한 것 같다, 그러나 나는 다음과 같은 오류를 얻고있다.

The type or namespace name 'BasicAckEventHandler' could not be found (are you missing a using directive or an assembly reference?) 

나는 rabbitmqdotnet의 DLL의 현재 버전을 사용하고 있습니다 : rabbitmqdotnet 클라이언트-3.6.5-DOTNET이-4.5

그것이 최근 버전에서 너무 BasicAckEventHandler 떨어져 사람들을 벌 수 있을까? 또는 나는 거기에 아무것도 놓치고 있습니까?

NB : 난, 난 결국 내 출판사를 쓴 방법, RabbitMqdotNet 사람이 이벤트 핸들러와 BasicAckEventHandler 유형을 대체

using RabbitMQ.Client; 
using RabbitMQ.Client.Events; 
+1

에 저를 지적 @ 크리스 더너웨이의 의견에 감사합니다. ** [이 게시물] (https://groups.google.com/forum/#!msg/rabbitmq-users/sPSP3ulG6sg/PksDKvISWOwJ) ** –

+0

Chris 님,이 사실을 확인해 주셔서 감사합니다. –

+0

@ChrisDunaway이 새로운 EventHander 를 사용하기 위해 위의 스크립트를 어떻게 변환 할 수 있는지 알고 계십니까? 이 줄을 변경해야합니까? _rabbitMqChannel.BasicAcks + = 새 BasicAckEventHandler (_rabbitMqChannel_BasicAcks); _rabbitMqChannel.BasicNacks + = 새 BasicNackEventHandler (_rabbitMqChannel_BasicNacks); –

답변

1

3.5.0에서 다음 using 문을 볼 수있다. 그들이`이벤트 핸들러 '에 찬성하는 이벤트를 제거 것으로 보인다이 link

public bool publish(string message) 
    { 
     var appSettings = config.getAppSettings(); 

     string HostName = appSettings["RABBITMQ_HOSTNAME"]; 
     string UserName = appSettings["RABBITMQ_USERNAME"]; 
     string Password = appSettings["RABBITMQ_PASSWORD"]; 

     var factory = new ConnectionFactory() 
     { 
      HostName = HostName, 
      UserName = UserName, 
      Password = Password 
     }; 

     using (var connection = factory.CreateConnection()) 
     using (var channel = connection.CreateModel()) 
     { 
      bool successful = false; 
      var responseReceivedEvent = new ManualResetEvent(false); 
      string exchangeName = appSettings["RABBITMQ_EXCHANGE"]; 
      string routingKey = appSettings["RABBITMQ_ROUTING_KEY"]; 
      Dictionary<string, object> headers = new Dictionary<string, object>(); 

      channel.BasicAcks += (model, args) => 
      { 
       successful = true; 
       responseReceivedEvent.Set(); 
      }; 

      channel.BasicNacks += (model, args) => 
      { 
       successful = false; 
       responseReceivedEvent.Set(); 
      }; 

      channel.ConfirmSelect(); 
      channel.ExchangeDeclare(exchangeName, ExchangeType.Topic, true, false, null); 
      var body = Encoding.UTF8.GetBytes(message); 
      IBasicProperties props = channel.CreateBasicProperties(); 
      props.ContentType = constants.RABBITMQ_MESSAGE_CONTENT_TYPE; 
      props.ContentEncoding = constants.RABBITMQ_MESSAGE_CONTENT_ENCODING; 
      props.DeliveryMode = constants.RABBITMQ_MESSAGE_DELIVERY_MODE_PERSISTENT; 
      props.MessageId = Guid.NewGuid().ToString(); 
      props.AppId = constants.APP_ID; 
      props.Type = constants.RABBITMQ_MESSAGE_TYPE; 
      props.Headers = (IDictionary<string,object>)headers; 
      props.Headers.Add("version", constants.VERSION); 
      props.Timestamp = new AmqpTimestamp(); 

      channel.BasicPublish(exchange: exchangeName, 
           routingKey: routingKey, 
           basicProperties: props, 
           body: body); 

      responseReceivedEvent.WaitOne(); 
      return successful; 
     } 

    }public bool publish(string message) 
    { 
     var appSettings = config.getAppSettings(); 

     string HostName = appSettings["RABBITMQ_HOSTNAME"]; 
     string UserName = appSettings["RABBITMQ_USERNAME"]; 
     string Password = appSettings["RABBITMQ_PASSWORD"]; 

     var factory = new ConnectionFactory() 
     { 
      HostName = HostName, 
      UserName = UserName, 
      Password = Password 
     }; 

     using (var connection = factory.CreateConnection()) 
     using (var channel = connection.CreateModel()) 
     { 
      bool successful = false; 
      var responseReceivedEvent = new ManualResetEvent(false); 
      string exchangeName = appSettings["RABBITMQ_EXCHANGE"]; 
      string routingKey = appSettings["RABBITMQ_ROUTING_KEY"]; 
      Dictionary<string, object> headers = new Dictionary<string, object>(); 

      channel.BasicAcks += (model, args) => 
      { 
       successful = true; 
       responseReceivedEvent.Set(); 
      }; 

      channel.BasicNacks += (model, args) => 
      { 
       successful = false; 
       responseReceivedEvent.Set(); 
      }; 

      channel.ConfirmSelect(); 
      channel.ExchangeDeclare(exchangeName, ExchangeType.Topic, true, false, null); 
      var body = Encoding.UTF8.GetBytes(message); 
      IBasicProperties props = channel.CreateBasicProperties(); 
      props.ContentType = constants.RABBITMQ_MESSAGE_CONTENT_TYPE; 
      props.ContentEncoding = constants.RABBITMQ_MESSAGE_CONTENT_ENCODING; 
      props.DeliveryMode = constants.RABBITMQ_MESSAGE_DELIVERY_MODE_PERSISTENT; 
      props.MessageId = Guid.NewGuid().ToString(); 
      props.AppId = constants.APP_ID; 
      props.Type = constants.RABBITMQ_MESSAGE_TYPE; 
      props.Headers = (IDictionary<string,object>)headers; 
      props.Headers.Add("version", constants.VERSION); 
      props.Timestamp = new AmqpTimestamp(); 

      channel.BasicPublish(exchange: exchangeName, 
           routingKey: routingKey, 
           basicProperties: props, 
           body: body); 

      responseReceivedEvent.WaitOne(); 
      return successful; 
     } 

    } 
관련 문제

 관련 문제