{"id":187994,"date":"2013-07-27T03:23:05","date_gmt":"2013-07-26T23:23:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=187994"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=187994","title":{"rendered":"<span class=\"post_title\">\u0421\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0432 Rails 4<\/span>"},"content":{"rendered":"<div class=\"content html_format\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d39\/24f\/6a0\/d3924f6a00b44b9d716e68a652d0eb94.jpg\" \/><\/div>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433?<\/h2>\n<p>  \u0421\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u043a\u0440\u0443\u0442\u0438\u043b\u0441\u044f \u043e\u043a\u043e\u043b\u043e Rails \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 3.2, \u043d\u043e \u043e\u043d \u0431\u044b\u043b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e <a href=\"http:\/\/apidock.com\/rails\/ActionController\/Streaming\">\u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u043e\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432<\/a>. Rails 4 \u0436\u0435 \u0432\u044b\u0448\u0435\u043b \u0441 \u0431\u043e\u043b\u0435\u0435 \u0437\u0440\u0435\u043b\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e Rails \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u043d\u0430\u0442\u0438\u0432\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c I\/O \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0432 \u0440\u0438\u0430\u043b\u0442\u0430\u0439\u043c\u0435.<\/p>\n<p>  Streaming \u0438 Live \u2014 \u0434\u0432\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 ActionController&#8217;\u0430. Streaming \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Live \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u044f\u0432\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435.<\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 api \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 Fiber (\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 ruby 1.9.2). \u0424\u0430\u0439\u0431\u0435\u0440\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u043e-\u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430 \u0432 ruby. Fiber \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0430\u043c \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430, \u0430 \u043d\u0435 \u0431\u044b\u0442\u044c \u043f\u043e \u0441\u0443\u0442\u0438 \u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e\u0449\u0438\u043c\u0438.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0421\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432<\/h2>\n<p>  \u0421\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u043b\u044d\u0439\u0430\u0443\u0442\u0430 \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Rails \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0448\u0430\u0431\u043b\u043e\u043d, \u0430 \u043f\u043e\u0442\u043e\u043c \u043b\u044d\u0439\u0430\u0443\u0442. \u041f\u0435\u0440\u0432\u043e\u0435 \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 <code>yield<\/code> \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e, \u0440\u0435\u043d\u0434\u0435\u0440\u044f\u0442\u0441\u044f \u0430\u0441\u0441\u0435\u0442\u044b \u0438 \u043b\u044d\u0439\u0430\u0443\u0442.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c action \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"ruby\">class TimelineController   def index     @users = User.all     @tickets = Ticket.all     @attachments = Attachment.all   end end<\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433. \u042d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0434\u043b\u044f Rails, \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433:<\/p>\n<pre><code class=\"ruby\">class TimelineController   def index     @users = User.all     @tickets = Ticket.all     @attachments = Attachment.all     render stream: true   end end <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 <code>render stream: true<\/code> \u043b\u0435\u043d\u0438\u0432\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0434\u0430\u0441\u0442 \u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0430\u0441\u0441\u0435\u0442\u044b \u0438 \u043b\u044d\u0439\u0430\u0443\u0442 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0440\u0435\u043d\u0434\u0435\u0440\u0435\u043d\u044b. \u0421\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043d\u0438\u043c\u0438 (\u043d\u043e \u043d\u0435 \u0441 json \u0438\u043b\u0438 xml). \u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0442\u0438\u043f\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438 \u0435\u0451 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u043c.<\/p>\n<h2>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0447\u0435\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u043d\u0443\u0442\u0440\u044c<\/h2>\n<p>  \u0421\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u043d\u0435\u0440\u0438\u043d\u0433\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0438 \u043b\u044d\u0439\u0430\u0443\u0442\u0430, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043b\u043e\u0433\u0438\u0447\u043d\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443: \u0430 \u043a\u0430\u043a \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445?<\/p>\n<p>  \u0412\u0435\u0434\u044c \u0442\u0430\u043a \u043a\u0430\u043a \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0449\u0435 \u043d\u0435 \u0432\u0435\u0440\u043d\u0443\u043b\u0430 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043a\u0430\u043a title \u0438 meta \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>content_for<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e <code>yield<\/code>&#8216;\u0430. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, <code>yield<\/code> \u0432\u0441\u0435 \u0435\u0449\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043b\u044f body.<\/p>\n<p>  \u0420\u0430\u043d\u0435\u0435 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"ruby\">&lt;%= yield :title %&gt; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"ruby\">&lt;%= content_for :title, &quot;My Awesome Title&quot; %&gt; <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0421\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u0436\u0438\u0432\u0435\u0435 \u0441 Live API<\/h2>\n<p>  Live \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 ActionController. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 Rails \u044f\u0432\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0438\u043c\u044b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u0440\u0438\u043c\u0443 \u0438\u0437\u0432\u043d\u0435.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430 \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430, WEBrick \u043d\u0430\u043c \u0442\u0443\u0442 \u043d\u0435 \u0442\u043e\u0432\u0430\u0440\u0438\u0449. \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Puma \u0438\u0431\u043e \u043e\u043d\u0430 \u0443\u043c\u0435\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0443\u043c\u0443 \u0432 Gemfile \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c bundle.<\/p>\n<pre><code class=\"ruby\">gem &quot;puma&quot; <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">:~\/testapp$ bundle install <\/code><\/pre>\n<p>  Puma \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 Rails, \u0442\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 <code>rails s<\/code>, Puma \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0441\u044f \u043d\u0430 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0440\u0442\u0443 \u0447\u0442\u043e \u0438 WEBRick.<\/p>\n<pre><code class=\"bash\">:~\/testapp$ rails s =&gt; Booting Puma =&gt; Rails 4.0.0 application starting in development on http:\/\/0.0.0.0:3000 =&gt; Run `rails server -h` for more startup options =&gt; Ctrl-C to shutdown server Puma 2.3.0 starting... * Min threads: 0, max threads: 16 * Environment: development * Listening on tcp:\/\/0.0.0.0:3000 <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e-\u0431\u044b\u0441\u0442\u0440\u043e\u043c\u0443 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"bash\">:~\/testapp$ rails g controller messaging <\/code><\/pre>\n<p>  \u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0438\u0445 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430.<\/p>\n<pre><code class=\"ruby\">class MessagingController &lt; ApplicationController   include ActionController::Live    def send_message     response.headers['Content-Type'] = 'text\/event-stream'     10.times {       response.stream.write &quot;This is a test Message\\n&quot;       sleep 1     }     response.stream.close   end end <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0440\u043e\u0443\u0442 \u0432 routes.rb:<\/p>\n<pre><code class=\"ruby\">get 'messaging' =&gt; 'messaging#send_message' <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u0440\u0438\u043c\u0443 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e curl:<\/p>\n<pre><code class=\"bash\">:~\/testapp$ curl -i http:\/\/localhost:3000\/messaging HTTP\/1.1 200 OK X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff X-UA-Compatible: chrome=1 Content-Type: text\/event-stream Cache-Control: no-cache Set-Cookie: request_method=GET; path=\/ X-Request-Id: 68c6b7c7-4f5f-46cc-9923-95778033eee7 X-Runtime: 0.846080 Transfer-Encoding: chunked This is a test message This is a test message This is a test message This is a test message <\/code><\/pre>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>send_message<\/code>, Puma \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Puma \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0447\u0442\u043e\u0431 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u043e 16 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 16 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0435\u043d\u0442\u043e\u0432. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c, \u043d\u043e \u044d\u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442 \u0440\u0430\u0441\u0445\u043e\u0434 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435-\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u043e\u0440\u043c\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 view:<\/p>\n<pre><code class=\"ruby\">def index end  def send_message   response.headers['Content-Type'] = 'text\/event-stream'   10.times {     response.stream.write &quot;#{params[:message]}\\n&quot;     sleep 1   }   response.stream.close end <\/code><\/pre>\n<p>  \u0414\u0435\u043b\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443 \u0434\u043b\u044f \u043f\u043e\u0441\u044b\u043b\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0442\u0440\u0438\u043c:  <\/p>\n<pre><code class=\"ruby\">&lt;%= form_tag messaging_path, :method =&gt; 'get' do %&gt;   &lt;%= text_field_tag :message, params[:message] %&gt;   &lt;%= submit_tag &quot;Post Message&quot; %&gt; &lt;% end %&gt; <\/code><\/pre>\n<p>  \u0418 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u0440\u043e\u0443\u0442\u044b:<\/p>\n<pre><code class=\"ruby\">root 'messaging#index' get  'messaging' =&gt; 'messaging#send_message', :as =&gt; 'messaging' <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0432\u0432\u0435\u0434\u0435\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u043d\u0430\u0436\u043c\u0435\u0442\u0435 \u00abPost Message\u00bb, \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432 \u0432\u0438\u0434\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0430\u0448\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0437\u0430\u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 10 \u0440\u0430\u0437.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/78d\/b70\/7c1\/78db707c19ffc5ed582391145ba31e2b.png\"\/><\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c, \u043e\u0434\u043d\u0430\u043a\u043e, \u0441\u0442\u0440\u0438\u043c \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043a\u0443\u0434\u0430 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0432 \u043a\u0430\u043a\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u043e \u043e\u043d \u0438\u0445 \u0438 \u043f\u0438\u0448\u0435\u0442 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e curl, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<pre><code class=\"ruby\">:~\/testapp$ curl -i http:\/\/localhost:3000\/messaging?message=&quot;awesome&quot; HTTP\/1.1 200 OK X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff X-UA-Compatible: chrome=1 Content-Type: text\/event-stream Cache-Control: no-cache Set-Cookie: request_method=GET; path=\/ X-Request-Id: 382bbf75-7d32-47c4-a767-576ec59cc364 X-Runtime: 0.055470 Transfer-Encoding: chunked awesome awesome <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0421\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (Server Side Events)<\/h2>\n<p>  HTML5 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 Server Side Events (SSE). SSE \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442 \u0438 \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043a\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SSE \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 Live API \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043b\u0430\u0434\u0438\u0442\u044c \u0434\u0432\u0443\u0445\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044e\u044e \u0441\u0432\u044f\u0437\u044c \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c.<\/p>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Rails \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044e\u044e \u043a\u043e\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u044e \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043d\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c SSE \u0442\u043e \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u043e\u0442\u0432\u0435\u0442\u044b \u0432 \u0434\u0432\u0443\u0445\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u043c \u0440\u0435\u0436\u0438\u043c\u0435.<\/p>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e\u0439 SSE \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"ruby\">require 'json'  module ServerSide   class SSE     def initialize io       @io = io     end      def write object, options = {}       options.each do |k,v|         @io.write &quot;#{k}: #{v}\\n&quot;       end       @io.write &quot;data: #{object}\\n\\n&quot;     end      def close       @io.close     end   end end <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 I\/O \u0441\u0442\u0440\u0438\u043c\u0430 \u0432 \u0445\u044d\u0448 \u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u0432 \u043f\u0430\u0440\u0443 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u043a\u043e \u0447\u0438\u0442\u0430\u0442\u044c, \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438 \u043e\u0442\u0441\u044b\u043b\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0430\u0448 \u0441\u0442\u0440\u0438\u043c-\u043e\u0431\u044a\u0435\u043a\u0442 \u0432 SSE. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c SSE \u043c\u043e\u0434\u0443\u043b\u044c \u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0442\u0440\u0438\u043c\u0430 \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f SSE \u043c\u043e\u0434\u0443\u043b\u0435\u043c. \u0422\u0430\u043a\u0436\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u044f\u0432\u043d\u043e, \u0446\u0438\u043a\u043b \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <code>ensure<\/code>, \u0447\u0442\u043e\u0431\u044b \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e \u0441\u0442\u0440\u0438\u043c \u0442\u0430\u043a\u0438 \u0437\u0430\u043a\u0440\u043e\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"ruby\">require 'server_side\/sse'  class MessagingController &lt; ApplicationController   include ActionController::Live    def index   end    def stream     response.headers['Content-Type'] = 'text\/event-stream'     sse = ServerSide::SSE.new(response.stream)     begin       loop do         sse.write({ :message =&gt; &quot;#{params[:message]}&quot; })         sleep 1       end     rescue IOError     ensure       sse.close     end   end end <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0442\u0432\u0435\u0442 \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<pre><code class=\"bash\">:~\/testapp$ curl -i http:\/\/localhost:3000\/messaging?message=&quot;awesome&quot; HTTP\/1.1 200 OK X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff X-UA-Compatible: chrome=1 Content-Type: text\/event-stream Cache-Control: no-cache Set-Cookie: request_method=GET; path=\/ X-Request-Id: b922a2eb-9358-429b-b1bb-015421ab8526 X-Runtime: 0.067414 Transfer-Encoding: chunked data: {:message=&gt;&quot;awesome&quot;} data: {:message=&gt;&quot;awesome&quot;} <\/code><\/pre>\n<p>  <\/p>\n<h2>\u041f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438<\/h2>\n<p>  \u0411\u0443\u0434\u044c\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b, \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u0430\u043c\u043d\u0435\u0439 (\u043a\u0443\u0434\u0430 \u0436 \u0431\u0435\u0437 \u043d\u0438\u0445 \u0442\u043e):<\/p>\n<ol>\n<li>\u0412\u0441\u0435 \u0441\u0442\u0440\u0438\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0437\u0430\u043a\u0440\u044b\u0442\u044b \u044f\u0432\u043d\u043e, \u0438\u043d\u0430\u0447\u0435 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b \u0432\u0441\u0435\u0433\u0434\u0430.<\/li>\n<li>\u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u0432\u0430\u0448 \u043a\u043e\u0434 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0435\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043c\u0435\u0442\u043e\u0434\u0430.<\/li>\n<li>\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0440\u0446\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u0445\u0435\u0434\u0435\u0440\u044b \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432 <code>write<\/code> \u0438\u043b\u0438 <code>close<\/code><\/li>\n<\/ol>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u042d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043d\u043e\u0433\u0438\u0435 \u0434\u0430\u0432\u043d\u043e \u0438\u0441\u043a\u0430\u043b\u0438 \u0432 Rails, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 (\u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432) \u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0443\u044e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044e node.js (Live).<\/p>\n<p>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0442, \u043d\u043e \u044f \u0434\u0443\u043c\u0430\u044e \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u043e\u0435 \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u043e\u0439\u0442\u0438 \u0432\u0440\u0435\u043c\u044f (\u0447\u0438\u0442\u0430\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043b\u0438\u0437\u043e\u0432) \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0430 \u0444\u0438\u0447\u0430, \u0442\u0430\u043a \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0434\u043e\u0437\u0440\u0435\u043b\u0430. \u0421\u0435\u0439\u0447\u0430\u0441 \u0436\u0435 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0441\u0442\u0430\u0440\u0442 \u0438 \u0432\u043e\u043b\u043d\u0443\u044e\u0449\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451 \u0432 \u0434\u0435\u043b\u0435.<\/p>\n<p>  PS: \u044d\u0442\u043e \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430, \u0431\u0443\u0434\u0443 \u043e\u0447\u0435\u043d\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d \u0437\u0430 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u0432 \u043b\u0438\u0447\u043a\u0443. \u0421\u043f\u0430\u0441\u0438\u0431\u043e.<\/p>\n<p>  \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b <a href=\"http:\/\/rubysource.com\/streaming-with-rails-4\/\">\u0442\u0443\u0442<\/a>.  \t\t\t\t<\/p>\n<div class=\"polling\">\n<form action=\"\/json\/polling\/\" class=\"poll\" method=\"post\">\n<div class=\"poll_title\">\u0421\u043c\u043e\u0436\u0435\u0442 \u043b\u0438 Rails \u0447\u0435\u0440\u0435\u0437 n \u043c\u0435\u0441\u044f\u0446\u0435\u0432\/\u043b\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u043d\u043e\u0439 Node.js \u0432 \u0440\u0435\u0430\u043b-\u0442\u0430\u0439\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445?<\/div>\n<p>  \t\t<input type=\"hidden\" name=\"post_id\" value=\"187994\"\/> \t\t<input type=\"hidden\" name=\"polling_question_id\" value=\"8534\"\/>  \t\t<\/p>\n<table class=\"answer\">\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv43682\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"43682\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv43682\">\u041b\u0435\u0433\u043a\u043e<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv43684\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"43684\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv43684\">\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0432\u043d\u044b<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv43686\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"43686\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv43686\">\u041d\u0438\u043a\u043e\u0433\u0434\u0430<\/label> \t\t\t\t<\/td>\n<\/tr>\n<\/table>\n<p class=\"for_users_only_msg\">\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a href=\"\/login\/\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/p>\n<p class=\"total\">\u041d\u0438\u043a\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b. \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u043d\u0435\u0442.<\/p>\n<\/p><\/form>\n<\/p><\/div>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/187994\/\"> http:\/\/habrahabr.ru\/post\/187994\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d39\/24f\/6a0\/d3924f6a00b44b9d716e68a652d0eb94.jpg\" \/><\/div>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433?<\/h2>\n<p>  \u0421\u0442\u0440\u0438\u043c\u0438\u043d\u0433 \u043a\u0440\u0443\u0442\u0438\u043b\u0441\u044f \u043e\u043a\u043e\u043b\u043e Rails \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 3.2, \u043d\u043e \u043e\u043d \u0431\u044b\u043b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e <a href=\"http:\/\/apidock.com\/rails\/ActionController\/Streaming\">\u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u043e\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432<\/a>. Rails 4 \u0436\u0435 \u0432\u044b\u0448\u0435\u043b \u0441 \u0431\u043e\u043b\u0435\u0435 \u0437\u0440\u0435\u043b\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0447\u0442\u043e Rails \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u043d\u0430\u0442\u0438\u0432\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c I\/O \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0432 \u0440\u0438\u0430\u043b\u0442\u0430\u0439\u043c\u0435.<\/p>\n<p>  Streaming \u0438 Live \u2014 \u0434\u0432\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 ActionController&#8217;\u0430. Streaming \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Live \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u044f\u0432\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435.<\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 api \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 Fiber (\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 ruby 1.9.2). \u0424\u0430\u0439\u0431\u0435\u0440\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u043e-\u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430 \u0432 ruby. Fiber \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0430\u043c \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430, \u0430 \u043d\u0435 \u0431\u044b\u0442\u044c \u043f\u043e \u0441\u0443\u0442\u0438 \u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e\u0449\u0438\u043c\u0438.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-187994","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/187994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187994"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/187994\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}