2018 m. sausio 21 d., sekmadienis

Sfinks

Quick start sphinx
$ sphinx-quickstart

Create folder for rst files
$ mkdir rst

Remove old rst files and generate rst, and make html files
$ rm -rf rst/ && sphinx-apidoc -f -o rst/ ../scripts_root/ && make htm

If you want to include all rst files in index.rst. cd to rst/ folder and run:
for f in *.rst; 
do printf 'rst/%s\n' "${f%.rst}" 
done

Gotcha:
If there is "-" in your folder structure, sphinx will trow error:
WARNING: invalid signature for automodule 

rabbitmq

RabitMQ - has libraries for favorite programming languages, and frameworks like spring, interface for web monitoring
RabbitMQ speaks the AMQP protocol by default.


Structure

Publisher (Producer) -  Publishes message to Message Broker
Message Broker - RabbitMQ [Exchange, [Queue, ..] ]
Exchange receives messages and directs them to the correct queue
Exchange type:

  • Direct - sends depending on  binding key.
  • Topic - sends based on wildcard.
  • Fanout - sends all queue, that ar bound to it.
Features:
  • Durable
    • exchanges will survive server restarts and will last until they are explicitly deleted.
  • Temporary 
    • exchanges exist until RabbitMQ is shutdown. 
  • Auto deleted
    •  exchanges are removed once the last bound object unbound from the exchange.
Consumer -  Consumes data. Subscribes.



Process

  1. Client applications called producers that create messages and deliver them to the broker (the message queue)
  2. Other applications, called consumers, connects to the queue and subscribes to the messages to be processed. Messages that are placed onto the queue are stored until the consumer retrieves them.




Concepts

Producer: Application that sends the messages. Consumer: Application that receives the messages. Queue: Buffer that stores messages. Message: Information that is sent from the producer to a consumer through RabbitMQ. Connection: A connection is a TCP connection between your application and the RabbitMQ broker. Channel: A channel is a virtual connection inside a connection. When you are publishing or consuming messages or subscribing to a queue, it is all done over a channel. Exchange: Receives messages from producers and pushes them to queues depending on rules defined by the exchange type. In order to receive messages, a queue needs to be bound to at least one exchange. Binding: A binding is a link between a queue and an exchange. Routing key: The routing key is a key that the exchange looks at to decide how to route the message to queues. The routing key is like an address for the message. AMQP: AMQP (Advanced Message Queuing Protocol) is the main protocol used by RabbitMQ for messaging. Users: It is possible to connect to RabbitMQ with a given username and password. Every user can be assigned permissions such as rights to read, write and configure privileges within the instance. Users can also be assigned permissions to specific virtual hosts. Vhost, virtual host: A Virtual host provides a way to segregate applications using the same RabbitMQ instance. Different users can have different access privileges to different vhosts and queues, and exchanges can be created so they only exist in one vhost.



Process


  • Set up connection.(Username, password)
  • Open channel in tcp connection.
  • Declare/create a queue
  • Subscriber/Consumer - Set up exchanges and bind a queue to an exchange. For messages to be routed to queue, queue need to be bound to exchange
  • Publisher: Publish message to echange
  • Subscriber/Consumer - Consume a message from queue.
  • Close the channel and the connection



Resources:

cloudamqp.com - cloudAMQP


Installing rabitmq:

https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-rabbitm

rabitmq status:
$ service rabbitmq-server status

enabling service:
$ chkconfig rabbitmq-server on

enable plugins:
$ sudo rabbitmq-plugins enable rabbitmq_management

cmd commands:
List exchanges:
$ sudo rabbitmqctl list_exchange

By default you can't login to remote console from external non-local.
How to enable logging  from remote machine to rabitmq console:

$ rabbitmqctl add_user YOUR_USERNAME YOUR_PASSWORD
$ rabbitmqctl set_user_tags YOUR_USERNAME administrator
$ rabbitmqctl set_permissions -p / YOUR_USERNAME ".*" ".*" ".*"


Problem:
By default rabitmq blocks loggins from remote ip adresses. How to enable remote login?

Solution:
Goto /etc/rabbitmq folder and create rabbitmq.conf with file content:
loopback_users = none


Problem:
Can't enable web access to http://localhost:15672  from Ubuntu 16.04.4 LTS to rabbitmq

Solution:
https://simpleit.us/2017/06/04/install-rabbitmq-on-ubuntu-16.04-lts/





python folder structure

Local python library location:

/usr/local/lib/python2.7/dist-packages/
/usr/lib/python3/dist-packages/