Blocking connection has no attribute 'basic' when called in a thread

Viewed 17

I have been trying to implement threading to rabbitmq service. I want to consume the queues from within the threads, created using the class shown bellow. Note that some of the imported files are created by me. I have implemented the following code:

import pika, sys, os
import SockAlertMessage_pb2, SockDataProcessedMessage_pb2, SockDataRawMessage_pb2, SockDataSessionEndMessage_pb2, SockDataSessionStartMessage_pb2, SockMessage_pb2
import numpy as np
import scipy 
import ampd
import python_file_3
import heartpy
import time 
import threading 

from  scipy.signal import detrend
from python_file_3 import filter_signal, get_hrv, get_rmssd, get_std, heart_rate
from ampd import find_peaks_original


amp = 2
freq = 1.2
time = np.arange(0,1500)
signal1 = amp*np.sin(2*np.pi*freq*time)

class Threaded_worker(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
        self.channel = self.connection.channel()
        self.channel.queue_declare(queue='sock_data_session_start_queue', durable = True)
        self.channel.queue_declare(queue='sock_data_session_end_queue', durable = True)
        self.channel.queue_declare(queue = 'sock_data_raw_queue', durable = True)
        self.channel.queue_declare(queue='tx_queue', durable = True)
        self.channel.basic_consume(queue='sock_data_session_start_queue', auto_ack=True, on_message_callback= self.sock_data_session_start_callback)
        self.channel.basic.comsume(queue = 'sock_data_session_end_queue', auto_ack = True, on_message_callback = self.sock_data_session_end_callback)
        self.channel.basic_consume(queue='sock_data_raw_queue', auto_ack=True, on_message_callback=self.sock_data_raw_callback)
        self.sequence_Id_list = []
        self.data_session_dict_start = {}
        self.data_session_dict_end = {}


   def add_sequence_id(self,new_value):
       self.sequence_Id_list(new_value)


   def sock_data_session_start_callback(ch, method, properties, body):
    
       message = SockDataSessionStartMessage_pb2.SockDataSessionStartMessage()
       message.ParseFromString(body)
       print('Sock data session number {} has started'.format(message.SockDataSessionId))
       self.data_session_dict_start['0'] = message.SockDataSessionId
    
   def sock_data_session_end_callback(ch, method, properties, body):
    
       message = SockDataSessionEndMessage_pb2.SockDataSessionEndMessage()
       message.ParseFromString(body)
       print(' data session number {} is ending'.format(message.SockDataSessionId))

   def sock_data_raw_callback(ch, method, properties, body):

       print('processing signal from data session {}'.format())
       message = SockDataRawMessage_pb2.SockDataRawMessage()
       message.ParseFromString(body)
       print('processing signal from data session {}'.format(message.SockDataSessionId))

I am actually new to threading and using rabbitmq. Firstly, I have made a class where I create a thread whenever a connection is made with a smart device. The challenge I am facing is with the channel.basic_consume command. It says that:

blockingchannel object has no attribute 'basic'

should I create another self statement for basic_consume in the innit definition? I have the pika and threading libraries up to date. Is there a key aspect that I am missing. Any help would be appreciated.

1 Answers

You have a couple typos here:

self.channel.basic.comsume

... should be:

self.channel.basic_consume

You should probably create a channel for each of the queues you're dealing with, as well.


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.

Related