amqp plugin: Put the connecting code into a separate function.