If you are accustomed to working with relational databases such as SQL Server, you might find it a bit strange how EASYNETQ handles connections. Communication with the relational database is always initiated by the client. The client opens the connection, issues a SQL command, processes the result if necessary, and then closes the connection. as a general recommendation, you should keep the connection open for as short a time as possible and leave the connection pool to the API.
talking to a message agent such as RABBITMQ is a little different because the connection tends to persist in the application's life cycle. Typically, you open a connection, create a subscription, and then wait for any message to reach an open connection. EASYNETQ does not assume that brokers are always available. Instead, it uses a deferred join method that polls a given endpoint on a background thread until it can connect. If the server disconnects for any reason (possibly a network failure, perhaps the RABBITMQ server itself has been bounced), EASYNETQ will resume polling the endpoint until it can reconnect.
A standard practice is to create a single IBUs instance within the lifetime of the application. Handle the application when it is closed.
A deferred connection to the RABBITMQ server is represented by the IBUs interface. Most EASYNETQ operations are methods on the IBUs. You create an instance of IBUs like this:
var bus = Rabbithutch.createbus ("host=myserver;virtualhost=myvirtualhost;username=mike;password= Topsecret ");
The connection string consists of key/value pairs in key = value format, each separated by a semicolon (;). The only required field is "host". The possible connection string values are:
- Host (for example, host = localhost or host = 192.168.2.56 or host = myhost.mydomain.com) This field is required. To specify the port to connect to, you can use the standard format host:port (for example, host = myhost.com:5673). If the port number is omitted, the default AMQP port (5672) is used. to connect to the RABBITMQ cluster, specify each cluster node separated by commas (for example, host = myhost1.com,myhost2.com,myhost3.com). for more information, see cluster support
- VirtualHost (e.g. VirtualHost = myvirtualhost) defaults to default virtual host '/'
- username (e.g. username = Mike) default to ' guest ' (for non ' localhost ' hosts, you need other users instead of ' guest ')
- Password (e.g. password = mysecret) default to ' guest '
- requestedheartbeat (e.g. requestedheartbeat = 10) defaults to 10 seconds. no heartbeat, set to zero.
- Prefetchcount (for example prefetchcount = 1) The default value is 50. This is the number of messages that RABBITMQ will pass before EASYNETQ sends an ACK. A setting of 0 means unlimited prefetching (not recommended). set to 1 to achieve a fair balance of work within the consumer community.
- publisherconfirms (for example, publisherconfirms = True) defaults to False. This will enable Publisher confirms.
- persistentmessages (for example, Persistentmessages = False) The default is true. This determines how the Delivery_mode in Basic.properties is set when the message is published. false = 1,true = 2. When set to True, RABBITMQ retains the message to disk and continues to exist after the server restarts. When set to false, performance gains can be expected.
- Product (e.g. Product = my really important service) was introduced in Easynetq 0.27.3. Default value is the name of the executable file that instantiates the bus. The values entered here will be displayed in the RABBITMQ management interface.
- Platform (for example, platform = My.fully.qualified.domain.name) is introduced in Easynetq 0.27.3. Default value is the host name of the computer on which the client process instantiates the bus. The values entered here will be displayed in the RABBITMQ management interface.
- Timeout(for example, timeout = 60) defaults to 10 seconds. introduced in Easynetq 0.17. resolves to a system.uint16 type. the range is from 0 to 65535. The format is in seconds. for an infinite timeout, use 0 to throw system.timeoutexception when the value is exceeded.
To close the connection, just handle the bus like this:
Bus. Dispose ();
This will close the EASYNETQ used by the connection, channel, consumer and all other resources.
Password[' Pɑ?sw?? D]DetailXBasic TranslationN. password;Network explanationPassword: Password confirm Password: Confirm Password admin Password: Manage password
"EASYNETQ Tutorial"-Connecting RABBITMQ