More diagnostics documentation

More diagnostics documentation
From a947b9d41ab15a013aeef870d0efe9325a17f468 Mon Sep 17 00:00:00 2001
From: Ben Langfeld <blangfeld@powerhrg.com>
Date: Thu, 6 Dec 2018 20:18:17 -0200
Subject: [PATCH] More diagnostics documentation


diff --git a/README.md b/README.md
index 964a6a0..d5405b3 100644
--- a/README.md
+++ b/README.md
@@ -133,6 +133,28 @@ You should see a reply with the messages of that channel you requested (in this
 
 MessageBus comes with a diagnostics interface, which you can access at `/message-bus/_diagnostics`. This interface allows you visibility into the runtime behaviour of message_bus.
 
+In order to use the diagnostics UI in your application, it is necessary to:
+
+* Enable it
+* Define a user ID for requests
+* Define a check for admin role
+
+as an example, you can do something like this:
+
+`‍``ruby
+MessageBus.enable_diagnostics # Must be called after `MessageBus.after_fork` if using a forking webserver
+
+MessageBus.user_id_lookup do |_env|
+  1
+end
+
+MessageBus.is_admin_lookup do |_env|
+  true
+end
+`‍``
+
+Of course, in your real-world application, you would define these values according to your authentication/authorization logic.
+
 ### Transport
 
 MessageBus ships with 3 transport mechanisms.
@@ -409,6 +431,18 @@ Rails.application.config do |config|
 end
 `‍``
 
+Specifically, if you use a Rack middleware-based authentication solution (such as Warden) in a Rails application and wish to use it for authenticating message_bus requests, you must ensure that the MessageBus middleware comes after it in the stack. Unfortunately, this can be difficult, but the following solution is known to work:
+
+`‍``ruby
+# config/initializers/message_bus.rb
+Rails.application.config do |config|
+  # See https://github.com/rails/rails/issues/26303#issuecomment-442894832
+  MyAppMessageBusMiddleware = Class.new(MessageBus::Rack::Middleware)
+  config.middleware.delete(MessageBus::Rack::Middleware)
+  config.middleware.insert_after(Warden::Manager, MyAppMessageBusMiddleware)
+end
+`‍``
+
 ### A Distributed Cache
 
 MessageBus ships with an optional `DistributedCache` API which provides a simple and efficient way of synchronizing a cache between processes, based on the core of message_bus:

GitHub