Skip to content

Instantly share code, notes, and snippets.

@zhuqling
Created March 11, 2013 03:39
Show Gist options
  • Save zhuqling/5131735 to your computer and use it in GitHub Desktop.
Save zhuqling/5131735 to your computer and use it in GitHub Desktop.
创建RabbitMQ连接和通道(包含publisher confirm), 关闭通道和连接
private readonly ConnectionFactory _connFactory = new ConnectionFactory();
private IConnection _conn;
private IModel _chan;
private const string Host = "192.168.1.200";
private const string UserName = "guest";
private const string Password = "guest";
private void InitRabbit()
{
_connFactory.HostName = Host;
_connFactory.UserName = UserName;
_connFactory.Password = Password;
_conn = _connFactory.CreateConnection();
_chan = _conn.CreateModel();
_chan.ConfirmSelect();
}
private void CloseRabbit()
{
_chan.Close();
_conn.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment