2016-09-28 23 views
0

C#でパブリッシャーの確認を実装しようとしています。型または名前空間の名前 'BasicAckEventHandler'が見つかりませんでした(usingディレクティブまたはアセンブリ参照がありませんか?)

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の男は のEventHandlerでBasicAckEventHandler種類を置き換え

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

に私を指摘@クリス・ダナウェイさんのコメントに おかげで彼らが 'のEventHandler 'の賛成で、それらのイベントが削除されたことと思われます。 ** [この投稿](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; 
     } 

    } 
関連する問題

 関連する問題