Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- JBoss JDK
- 1024k
- AWS module 1
- log4j 보안취약
- RabbitMQ Python
- webserver cors
- AWS Practitioner 공부
- Stack Size
- WebLogic 사설인증서
- WebLogic log4j
- Tomcat
- AWS Certified Cloud Practitioner
- iPlanet7
- weblogic jersey
- org.glassfish.jersey.internal.Errors logErrors
- JBoss OS
- JBoss7
- OPSS DemoIdentity
- WebLogic 데모 인증서 먼저 인식
- 다테 민속촌
- iPlanet cors
- jersey servlet error
- was log4j
- JBoss Support
- RabbitMQ Tuttorials
- RabbitMQ 테스트
- ClassNotdefFound
- ams 자격증 준비
- weblogic 500 error
- WebLogic Stack Size
Archives
- Today
- Total
개인 저장용 블로그
RabbitMQ Tutorials - Hello Wolrd (3) 본문
이번 목차는 메시지 큐를 단순하게 보내고 받을 수 있는 내용입니다.
사용 가능한 언어로는 Python, Java Ruby, PHP, C#, JavaScript, Go, Elixir, Objective-C, Swift, Spring AMQP 가 있지만, Python 으로 진행 할 예정입니다.
1.2.1.1. Python
- Python 소스 코드 작성
Send.py
#!/usr/bin/env python import pika # RabbitMQ Server 연결 # 다른 시스템에 연결 하려면 localhost 부분에 IP 주소 입력 connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() # Message Queue 생성 channel.queue_declare(queue='hello') # RabbitMQ의 Message는 Queue로 직접 보낼 수 없으며 항상 exchange를 거쳐야 함 channel.basic_publish(exchange='', routing_key='hello', body='Hello World!') print(" [x] Sent 'Hello World!'") # 연결닫기 connection.close() |
Recevice.py
#!/usr/bin/env python import pika, sys, os def main(): connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) channel = connection.channel() channel.queue_declare(queue='hello') def callback(ch, method, properties, body): print(" [x] Received %r" % body) channel.basic_consume(queue='hello', on_message_callback=callback, auto_ack=True) print(' [*] Waiting for messages. To exit press CTRL+C') channel.start_consuming() if __name__ == '__main__': try: main() except KeyboardInterrupt: print('Interrupted') try: sys.exit(0) except SystemExit: os._exit(0) |
- Message Queue테스트
# message queue 받을 준비
root@master:/product/python# python3 recevice.py
[*] Waiting for messages. To exit press CTRL+C |
위의 py 파일을 실행 한 후 종료 하지 않는다.
# message queue 보내기
root@master:/product/python# python3 send.py
[x] Sent 'Hello World!' |
# 받은 message queue 확인하기
root@master:/product/python# python3 recevice.py
[*] Waiting for messages. To exit press CTRL+C [x] Received b'Hello World!' |
Recevice 에서 ‘Hello World!’ 라는 queue를 받는 것을 확인 할 수 있다.
- RabbitMQ Console 확인
‘queue’ 태그를 확인 해 보면 overview 에 hello라는 queue를 확인 할 수 있다.
'오픈소스 > RabbitMQ' 카테고리의 다른 글
RabbitMQ Tutorials - Routing (6) (0) | 2022.04.04 |
---|---|
RabbitMQ Tutorials - Publish/Subscribe (5) (0) | 2022.04.04 |
RabbitMQ Tutorials - Work queues (4) (0) | 2022.04.04 |
RabbitMQ Tutorials - Python 환경구성 (2) (0) | 2022.04.04 |
RabbitMQ Tutorials - Downloading and install RabbitMQ (1) (0) | 2022.04.04 |