How to use the pika.spec function in pika

To help you get started, we’ve selected a few pika examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Vanlightly / RabbitMq-PoC-Code / ConsistentHashing / RabbitMqSummit / python / client / send-state-updates-direct.py View on Github external
acks = 0
            messages_to_remove = [item for item in pending_messages if item <= frame.method.delivery_tag]
            for val in messages_to_remove:
                try:
                    pending_messages.remove(val)
                except:
                    print(f"Could not remove multiple flag message: {val}")
                acks += 1
        else:
            try:
                pending_messages.remove(frame.method.delivery_tag) 
            except:
                print(f"Could not remove non-multiple flag message: {frame.method.delivery_tag}")
            acks = 1

    if isinstance(frame.method, spec.Basic.Ack):
        pos_acks += acks
    elif isinstance(frame.method, spec.Basic.Nack):
        neg_acks += acks
    elif isinstance(frame.method, spec.Basic.Return):
        print("Undeliverable message")
    

    curr_ack = int((pos_acks + neg_acks) / 10000)
    if curr_ack > last_ack:
        print(f"Pos acks: {pos_acks} Neg acks: {neg_acks}")
        last_ack = curr_ack

    if (pos_acks + neg_acks) >= total:
        print(f"Final Count => Pos acks: {pos_acks} Neg acks: {neg_acks}")
        connection.close()
        exit(0)
github robomq / robomq.io / sdk / AMQP / Python / one-to-one / producer.py View on Github external
server = "hostname"
port = 5672
vhost = "yourvhost"
username = "username"
password = "password"
routingKey = "testQ"

try:
	#connect
	credentials = pika.PlainCredentials(username, password)
	connection = pika.BlockingConnection(pika.ConnectionParameters(host = server, port = port, virtual_host = vhost, credentials = credentials, heartbeat_interval = 60))
	channel = connection.channel()

	#send message
	#assigning blank string to exchange is to use the default exchange, where queue name is the routing key
	properties = pika.spec.BasicProperties(content_type = "text/plain", delivery_mode = 1)
	channel.basic_publish(exchange = "", routing_key = routingKey, body = "Hello World!", properties = properties)

	#disconnect
	connection.close()
except Exception, e:
	print e
github pika / pika / pika / asyncore_adapter.py View on Github external
def connect(self, host, port):
        self.dispatcher = RabbitDispatcher(self)
        self.dispatcher.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.dispatcher.connect((host, port or pika.spec.PORT))
github programa-stic / marvin-django / marvin / frontpage / queue_handler.py View on Github external
ch = connection.channel()

		success = False

		response = ch.queue_purge(queue=agent_settings.download_queue)
		if pika.spec.Queue.PurgeOk == type(response.method):
			success = True
			print "Se vaciaron ", response.method.message_count, " mensajes de " + agent_settings.download_queue

		response = ch.queue_purge(queue=agent_settings.androlyze_queue)
		if pika.spec.Queue.PurgeOk == type(response.method):
			success = True
			print "Se vaciaron ", response.method.message_count, " mensajes de " + agent_settings.androlyze_queue
		
		response = ch.queue_purge(queue=agent_settings.process_queue_vuln)
		if pika.spec.Queue.PurgeOk == type(response.method):
			success = True
			print "Se vaciaron ", response.method.message_count, " mensajes de " + agent_settings.process_queue_vuln
		
		connection.close()

	except Exception as e:
		logging.error("Error vaciando agentes: " + repr(e) + "\n")
github pika / pika / pika / template.py View on Github external
    def connect(self, host='localhost', port=spec.PORT, vhost='/',
                username='guest', password='guest'):
        pass
github robomq / robomq.io / sdk / AMQP / Python / topic / producer.py View on Github external
server = "hostname"
port = 5672
vhost = "yourvhost"
username = "username"
password = "password"
exchangeName = "testEx"
routingKey = "test.any"

try:
	#connect
	credentials = pika.PlainCredentials(username, password)
	connection = pika.BlockingConnection(pika.ConnectionParameters(host = server, port = port, virtual_host = vhost, credentials = credentials, heartbeat_interval = 60))
	channel = connection.channel()

	#send message
	properties = pika.spec.BasicProperties(content_type = "text/plain", delivery_mode = 1)
	channel.basic_publish(exchange = exchangeName, routing_key = routingKey, body = "Hello World!", properties = properties)

	#disconnect
	connection.close()
except Exception, e:
	print e
github pika / pika / examples / twisted_service.py View on Github external
def send_message(self, exchange, routing_key, msg):
        """Send a single message."""
        log.msg(
            '%s (%s): %s' % (exchange, routing_key, repr(msg)),
            system='Pika:=>')
        yield self._channel.exchange_declare(
            exchange=exchange,
            exchange_type='topic',
            durable=True,
            auto_delete=False)
        prop = spec.BasicProperties(delivery_mode=2)
        try:
            yield self._channel.basic_publish(
                exchange=exchange,
                routing_key=routing_key,
                body=msg,
                properties=prop)
        except Exception as error:  # pylint: disable=W0703
            log.msg('Error while sending message: %s' % error, system=self.name)
github rabbitinaction / sourcecode / python / chapter-2 / hello_world_producer_pubconfirm.py View on Github external
def confirm_handler(frame): #/(hwppc.1) Publisher confirm handler
    if type(frame.method) == spec.Confirm.SelectOk:
        print "Channel in 'confirm' mode."
    elif type(frame.method) == spec.Basic.Nack:
        if frame.method.delivery_tag in msg_ids:
            print "Message lost!"
    elif type(frame.method) == spec.Basic.Ack:
        if frame.method.delivery_tag in msg_ids:
            print "Confirm received!"
            msg_ids.remove(frame.method.delivery_tag)
github allenling / magne / magne / helper.py View on Github external
async def declare_exchange(self, channel_number, name):
        exchange_declare = pika.spec.Exchange.Declare(exchange=name)
        frame_value = pika.frame.Method(channel_number, exchange_declare)
        await self.sock.sendall(frame_value.marshal())
        await self.assert_recv_method(pika.spec.Exchange.DeclareOk)
        return Exchange(name=name)
github pika / pika / pika / frame.py View on Github external
def __init__(self):
        """Create a new instance of the Heartbeat frame"""
        Frame.__init__(self, spec.FRAME_HEARTBEAT, 0)