
AMQP-REST
talked about AMQP a lot. The next development focused on AJAX.
Opportunities:
Data is returned in JSON.
reading one element from the queue, the
name of the queue is the right part of the url until the last slash. For url / sss / q2, the queue name is “q2”. This is done intentionally, since all urls are hung on a specific location and proxied through nginx. reading all elements from the queue queue size publication The exchange name is also the part of the url between the last slash and '?', and the exchange key is the part of the url, after the question mark. For example, for url 10.0.0.1 : 8080 / sss / ex1? News , the exchange name is “ex1”, and the routing key is “news”
Of course, everything is designed for AJAX. nginx stands at the front of the server and proxies requests for amqp-rest. You can do without nginx if you hang them on different IPs. In my case, I use ngx_accesskey_module to protect against spam. Perhaps this functionality will be transferred to amqp-rest in the future.
that repents of performance: 1300rps
memory space 601k
Opportunities:
- read one message from the queue
- read all messages from the queue
- find out the length of the queue
- post a message in exchange
Data is returned in JSON.
Assembly
- install libevent (available in ports, already installed on most servers) monkey.org/~provos/libevent
- install rabbitmq-c hg.rabbitmq.com/rabbitmq-c
- install protocol code-generation hg.rabbitmq.com/rabbitmq-codegen
- install amqpcpp code.google.com/p/rabbitcpp
- run the makefile;
- copy amqp-rest to / usr / local / bin
- edit n.conf and copy to /usr/local/etc/amqp-rest.conf
logfile /usr/local/var/amqp.log; # logfile
pidfile /tmp/amqp.pid; # pidfile
log_level notice; # the level of logging: error, notice, warning, debug
daemon on; # daemon mode
port 80; # http port, default 80
http 10.0.0.1; # bind IP
amqp: 5672; # amqp connection string psw: login @ host: port / vhost
Launch
./amqp-rest [полное имя конфиг-файла]
./amqp-rest stop // останавливает сервис
kill -s HUP `ps | grep amqp-rest | awk '{print $1}'` // перезапуск с новой конфигурацией
Using
reading one element from the queue, the
name of the queue is the right part of the url until the last slash. For url / sss / q2, the queue name is “q2”. This is done intentionally, since all urls are hung on a specific location and proxied through nginx. reading all elements from the queue queue size publication The exchange name is also the part of the url between the last slash and '?', and the exchange key is the part of the url, after the question mark. For example, for url 10.0.0.1 : 8080 / sss / ex1? News , the exchange name is “ex1”, and the routing key is “news”
curl 10.0.0.1:8080/sss/q2
{"result": "OK", "message":"message 2", size : 2}
// size - размер очереди, сколько элементов осталось в очереди.
curl 10.0.0.1:8080/sss/q2?all
{"result": "OK", "count" : 2, messages ["message 3","the text\"xxxx\" tttt"]}
// count - размер массива сообщений.
curl 10.0.0.1:8080/sss/q2?count
{"result": "Ok", "count": 3 }
curl -d 'some post data' 10.0.0.1:8080/sss/ex1?news
{"result": "Ok"}
Of course, everything is designed for AJAX. nginx stands at the front of the server and proxies requests for amqp-rest. You can do without nginx if you hang them on different IPs. In my case, I use ngx_accesskey_module to protect against spam. Perhaps this functionality will be transferred to amqp-rest in the future.
conclusion
that repents of performance: 1300rps
memory space 601k