Dispatcher

 Basic:

There are two basic approach to web publishing.

i) Static web servers

ii) Content management servers.


Static web servers:

Static web servers such as Apache, IIS are very simple and fast. One of the greatest feature of the static web servers is that they are expandable by third party plugins.

Apache came as open source. To increase the no. of open source software, apache came with Apache open source felix (OSGI implementation), Jackrabit (JCR) and Sling.


Content management servers:

Content management servers provide dynamic, real time and intelligent content but required more processing and other resource.


                                                        AEM Dispatcher

The dispatcher combines the speed of static webserver with flexibility of CMS. The dispatcher operates as part of a static HTML server (Such as apache)

 Flow

Such environment provides caching with aim of :

 1. Caching as much of the site content as possible inform of static website

 2. Accessing the layout engine as little as possible.

It means that:

a. Static content is handled with exactly the same speed as static web server in additionally you can use the administration and security tool from dispatcher.  Few static web servers are Apache HTTS server; microsoft IIS; Oracle Iplanet.

b. Dynamic content is generated as needed without slowing the system down.


 --> Load Balancing is the practice of distributing the computational load of the website across several instances of AEM.

The goal of dispatcher:


a. Caching

b. Load Balancing


The dispatcher provides:

a. Security

b. Request processing management

 

                                                 Environment Setup

1. Select on of the three supported static web servers and install it.

 a. Apache HTTP server (httpd)

b. Microsoft IIS

c. Oracle Iplanet.

2. Install and enable AEM Dispatcher module (Plugin) for the selected static web server.


Example - Appache HTTP server

 From Adobe website you need to download and install "dispatcher-apache-x.x.window-x86,zip" plugin.

Then from apace website download "Apache httpd"

Do the proper configuration  --> httpd.conf add following lines.

 --> Dispatcher config

--> Dispatcher log

--> Dispatcher logLevel

--> Dispatcher user processURL


    Enabling Cache

Caching is key for performance but also create lot of issue if configurated incorrectly. By default resource will be cached if below condition satisfied:

 --> HTTP request method is GET

--> Request URL has no query string

--> Request URL has extension (eg: html,xml.css,js)

--> Request has no "Authorization" header.


All the dispatcher setting are in config/dispatcher.any. This configuration file contains a series of single value or multivalued properties that control behavior of dispatcher.

--> property names are prefixed with a forward slash ("/")

--> multi-valued properties enclose child items using braces ("{}").

--> Comments start with "#"


Four section for dispatcher any:

1. Renders

2. Filters

3. Cache

4. Headers.


RENDERS: Renders are AEM instance from which dispatcher received content(it may be cached). Renders are the first things we will define in our configuration file. 

If we define more then one render, the dispatcher will automatically balance the load among these AEM instance.

Eg with one render:

  /renders

      {
      /rend01
        {
        /hostname "localhost"
        /port "4503"
        }
      }

(NOTE: We don't need port in the dispatcher request URL as it will work on port 80 which is default for all browser)


FILTERS: The /filter section specifies HTTP requests that dispatcher can accept. All other requests are sent back to the web server with a 404 error code (page not found). Let’s allow access to all the resources for our demonstration case.

 /filter
      {
      /0001 { /type "allow" /glob "*" }
      }

Filters types: “allow” or “deny”.

Globs will be compared against the entire request line, e.g.:

/0001 { /type "allow" /glob "* /index.html *" }

This glob matches request “GET /index.html HTTP/1.1” but not “GET /index.html?a=b HTTP/1.1”.


Instead of “globs” you may use separate “url”, “method”, “protocol”, “extension” to define your filter In addition to “url” you may use “path”, “selectors”, “extension”, “suffix”

NOTE: When a request fits multiple filter patterns then only the last filter pattern is applied.

CACHE : Cache section determines resources that will be cached by dispatcher. This is similar to the filters rules.

(Eg:  /docroot determines location of the directory where cached files are stored.)

 /cache
      {
      /docroot "/Apache22/htdocs"
      /rules
        {
        /0000
          {
          /glob "*"
          /type "allow"
          }
        }
      }

HEADER: Cached file only contains html content. if response from renders contains “Content-Type” header which determines encoding, the html content may not be displayed correctly without the header.

/cache
{
      /headers
        {
        "Cache-Control"
        "Content-Disposition"
        "Content-Type"
        "Expires"
        "Last-Modified"
        "X-Content-Type-Options"
        }
}

AUTOMATIC INVALIDATION AND FULSH AGENT

For automatic invalidation purposes you may enable author or publish flush agents. It’s recommended to use publish flush agent for more robust auto-invalidation because using author flush agent may cause next issues:

 A. The Dispatcher must be reachable from the authoring instance. If your network (e.g. the firewall) is configured such that access between the two is restricted this may not be the case.

B. Publication and cache invalidation take place at the same time. Depending on the timing a user may request a page just after it was removed from the cache and just before the new page is published. AEM now returns the old page and the Dispatcher caches it again. This is more of an issue for large sites.

Publish flush agent is located at http://localhost:4503/etc/replication/agents.publish/flush.html



To enable your publish flush agent click “Edit” button and set “Enabled” checkbox:
Update URI port on the Transport tab and set it value to 80:


Save your updates and you will see that publish flush agent has been enabled:



USEFUL TOOLS:

Below I’m describing a few useful tools for advanced using of the dispatcher:

 -->static web servers tools
        rewrite module
-->AEM tools for mappings
        repository mappings tree /etc/map
        ResourceProvider Interface

Rewrite Module: We can enable rewrite module by updating .conf file in IIS/httpd.
Repository mappings tree /etc/map :  Repository mappings is used to define redirects, vanity URLs and virtual hosts for AEM.
 How to create: 
1. Create node under /etc/map/http with type “sling:Mapping” with name “localhost_any”;
2. Add properties to this node:
        a. Name “sling:match”, type “String”, value “localhost.4503/”;
        b. Name “sling:internalRedirect”, type “String”, value “/content/”.

ResourceProvider interface
You may use ResourceProvider interface for creation of your own resource trees in java.

public interface ResourceProvider {
    Resource getResource(ResourceResolver var1, String var2);
    Iterator<Resource> listChildren(Resource var1);
}
You may set root paths for your implementation of the ResourceProvider:
@Properties({
       @Property(
               label = "Root paths",
               description = "Root paths this Sling Resource Provider will respond to",
               name = ResourceProvider.ROOTS,
               value = {"/content/testing/samples"})
})

Comments

Popular posts from this blog

First AI project

AEM with react.

Sling Servlet