 			vhost: domain || '/'
 		self.connection.on 'error', (Message) ->
 			console.log "Connection error", Message
+			self.connection.close()
+			self.connect(domain,setup)
 		self.connection.on 'end', () ->
 			console.log "Connection closed"
+			self.connection.close()
+			self.connect(domain,setup)
 		self.connection.on 'ready', () ->
 			console.log "Connection ready"
 			setup()

	self.delete = (queue) ->
		# deletes a queue, unbinding it in the proces
		if not self.queues[queue]
			self.connection?.queue queue, (Queue) ->
				Queue.destroy()
		else
			self.queues[queue]?.destroy()

			self.queues[queue].unsubscribe socket.ctag
	self.subscribe = (queue,socket,listener) ->
		if not self.queues[queue]
			self.connection?.queue queue, { arguments: { "x-message-ttl" : 60000 } }, (Queue) ->
				self.queues[queue] = Queue
				(Queue.subscribe { ack: false, prefetchCount: 1 }, (message, headers, deliveryInfo) ->
					listener(message.data.toString())
