def call_javascript_microservice(interviewers, candidate, data): emails = [] for interviewer in interviewers: emails.append(interviewer.email) emails.append(candidate.email) print(emails) # json data for send on microservice json_to_microservice = { "title": "create", "body": { "id_event": "", "begin_time": data['begin_time'], "end_time": data['begin_time'], "email": emails, "phone": data['phone'], "location": data['location'], "description": data['description'] } } json_to_microservice = json.dumps(json_to_microservice) rabbitmq = RabbitMQ(host=settings.RABBITMQ_HOST, user=settings.RABBITMQ_USERNAME, password=settings.RABBITMQ_PASSWORD) rabbitmq.call(exchange_name='js-backend', exchange_type='direct', queue_to_send='event', routing_key_to_send='event', queue_to_receive='event-response', message=json_to_microservice) data_json = rabbitmq.response.decode('utf-8') data_json = json.loads(data_json)
def send_message_to_java(queryset, serializer): rabbit = RabbitMQ(host=settings.RABBITMQ_HOST, user=settings.RABBITMQ_USERNAME, password=settings.RABBITMQ_PASSWORD) content = rabbit.call_java(queryset, serializer, exchange_name='share', q_receiving='shareResponse', q_sending='facebook.publish') content = content.decode('utf-8') content = json.loads(content) vacancy = Vacancy.objects.get(uuid=content['uuid']) user = User.objects.get(email=vacancy.created_by) data = { "vacancy": vacancy, "created_by": user, "message": content['message'], "url": content['url'], "status": content['status'], "publisher_service": content['publisher_service_type'] } Publication.objects.create(**data)
def delete(self, request, pk, *args, **kwargs): data = {"title": "DELETE", "id": pk} data = json.dumps(data) print(type(data), data) rabbitmq_sender = RabbitMQ(user=settings.RABBITMQ_USERNAME, password=settings.RABBITMQ_PASSWORD) rabbitmq_sender.call(exchange_name='exchangeForTemplate', exchange_type='direct', queue_to_send='template', routing_key_to_send='template', queue_to_receive='template3', message=data) response_data = rabbitmq_sender.response.decode('utf-8') response_data = json.loads(response_data) return Response(response_data)
def delete(self, request, pk, *args, **kwargs): data = {"title": "DELETE", "id": pk} data = json.dumps(data) rabbitmq_sender = RabbitMQ(host=settings.RABBITMQ_HOST, user=settings.RABBITMQ_USERNAME, password=settings.RABBITMQ_PASSWORD) rabbitmq_sender.call(exchange_name='js-backend', exchange_type='direct', queue_to_send='template', routing_key_to_send='template', queue_to_receive='template-response', message=data) response_data = rabbitmq_sender.response.decode('utf-8') response_data = json.loads(response_data) return Response(response_data, status=status.HTTP_204_NO_CONTENT)
def get(self, request, *args, **kwargs): data = {'title': 'FIND_ALL'} data = json.dumps(data) rabbitmq_sender = RabbitMQ(host=settings.RABBITMQ_HOST, user=settings.RABBITMQ_USERNAME, password=settings.RABBITMQ_PASSWORD) rabbitmq_sender.call(exchange_name='js-backend', exchange_type='direct', queue_to_send='template', routing_key_to_send='template', queue_to_receive='template-response', message=data) response_data = rabbitmq_sender.response.decode('utf-8') response_data = json.loads(response_data) return Response(response_data, status=status.HTTP_200_OK)
def post(self, request, *args, **kwags): data = request.data data['title'] = 'CREATE' data = json.dumps(data) print(type(data), data) rabbitmq_sender = RabbitMQ(user=settings.RABBITMQ_USERNAME, password=settings.RABBITMQ_PASSWORD) rabbitmq_sender.call(exchange_name='exchangeForTemplate', exchange_type='direct', queue_to_send='template', routing_key_to_send='template', queue_to_receive='template3', message=data) response_data = rabbitmq_sender.response.decode('utf-8') response_data = json.loads(response_data) return Response(response_data)
def post(self, request, *args, **kwags): data = request.data data['title'] = 'CREATE' rabbitmq_sender = RabbitMQ(host=settings.RABBITMQ_HOST, user=settings.RABBITMQ_USERNAME, password=settings.RABBITMQ_PASSWORD) rabbitmq_sender.call(exchange_name='js-backend', exchange_type='direct', queue_to_send='template', routing_key_to_send='template', queue_to_receive='template-response', message=data) response_data = rabbitmq_sender.response.decode('utf-8') response_data = json.loads(response_data) response_data.pop('title') return Response(response_data, status=status.HTTP_201_CREATED)