First, install Erlang and the RabbitMQ server which can both be found under Message Queues with RabbitMQ
Question:
First, install Erlang and the RabbitMQ server which can both be
found under Message Queues with RabbitMQ Resources located on the Message Queues
With RabbitMQ Assignment page for your operating system. Finally, for protocol support you
will need to install the Pika module. From PyCharm inside your project go to File > Settings >
Project Settings > Project Interpreter. From there click on the green "+" to add a package to the
project. Enter Pika in the search field at the top and select Add Package.
Now, you will need two Python source files. One sender (send.py) and one receiver (receive.py).
The sender will need establish a connection, channel and declare a queue. It will then need to
send a message to the message queue once per second. You may use a while loop and the
time.sleep function for this. The message should be something unique, like "My name is John
Doe and I love Python! #" where is # is a running counter so you can see the message number.
Each of the receivers, will need to establish a connection to the same queue, register a call back,
and start consuming any messages received. When a message is received it should be output to
standard out.
This assignment is not very realistic when implemented on a single computer but recognize that
"localhost" need not be the address. The message queue could be located on one server with
dozens of senders and receivers each located anywhere.
As you are running your code, noticed that you can start the server. It will begin sending
messages. Wait a few seconds and start the receiver. Notice that all messages are received even
though some were sent before the receiver was started. This is one of the benefits of message
queues, i.e. it maintains the message history and can deliver messages to clients even if they
momentarily lose connectivity.
Hint
Be sure to review the RabbitMQ Tutorials which can be found under the Message Queues
with RabbitMQ Resources. Not only will they help with the assignment, they also contain very
good information about message queues in general.
Test your code completely. At each step of the test take a screen shot and embed it into a Word
document. Submit the Word document to the appropriate assignment.
Submit the source files and any other relevant material.
Below is my current code for the Sender.py:
import sysv_ipc
import numpy as np
import struct
BUFF_SIZE = 20
msg_string = "My name is Anthony Taylor II and I absolutely love Python! #"
msg_double1 = 1234.56789
msg_double2 = 9876.12345
msg_npy = np.arange(BUFF_SIZE, dtype=np.uint8).reshape((2, BUFF_SIZE // 2))
msg_npy_half = np.arange(BUFF_SIZE // 2, dtype=np.uint8).reshape((2, BUFF_SIZE // 4))
try:
mq = sysv_ipc.MessageQueue(1234, sysv_ipc.IPC_CREAT)
# string transmission
mq.send(msg_string, True, type=1)
# Two double transmission
bytearray1 = str(struct.pack("d", msg_double1))
bytearray2 = str(struct.pack("d", msg_double2))
mq.send(bytearray1 + bytearray2, True, type=1)
# numpy array transmission
mq.send(msg_npy.tobytes(order='C'), True, type=1)
# one double one numpy transmission
bytearray1 = str(struct.pack("d", msg_double1))
mq.send(bytearray1 + msg_npy_half.tobytes(order='C'), True, type=1)
except sysv_ipc.ExistentialError:
print
"ERROR: message queue creation failed"
Below is my code for receiver.py:
import sysv_ipc
import numpy as np
import struct
BUFF_SIZE = 16
try:
mq = sysv_ipc.MessageQueue(1234, sysv_ipc.IPC_CREAT)
while True:
message = mq.receive()
print message
except sysv_ipc.ExistentialError:
print "ERROR: message queue creation failed"
The system is saying that the import for sysv_ipc does not exist and I cannot get the code to run. Is the code incorrect for this assignment?
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill