Skip to main content

Administrator Guide

This guide covers the day-to-day administration of Integration Hub for Moodle: registering services, creating event rules, monitoring the dashboard, and managing the Dead Letter Queue.


Accessing the Plugin

Navigate to /local/integrationhub/index.php or use the Services tab in the plugin navigation.

The plugin has four main sections:

TabURLDescription
Services/local/integrationhub/index.phpRegister and manage external services
Rules/local/integrationhub/rules.phpCreate Event Bridge rules
Queue/local/integrationhub/queue.phpMonitor the Dead Letter Queue
Events/local/integrationhub/events.phpView sent event log

Managing Services

Adding a REST/HTTP Service

  1. Go to the Services tab
  2. Click Add Service
  3. Fill in the form:

Basic Settings

FieldDescriptionExample
NameUnique slug. No spaces. Used in PHP calls: mih::request('this-name', ...)notification-api
TypeTransport protocolREST
Base URLRoot URL. Endpoint paths are appended to thishttps://api.example.com/v1
EnabledToggle to activate/deactivate without deletingchecked

Authentication

FieldDescriptionExample
Auth TypeBearer sends Authorization: Bearer {token}. API Key sends X-API-Key: {token}Bearer
Token / API KeyThe credential valueeyJhbGci...

Resilience Settings

FieldDescriptionRecommended
Timeout (s)Seconds before the request is cancelled5
Max RetriesAdditional attempts after the first failure3
Initial Backoff (s)Seconds before the first retry. Doubles each attempt1
CB Failure ThresholdConsecutive failures before the circuit opens5
CB Cooldown (s)Seconds before the circuit attempts recovery (HALFOPEN)30

Constructed Request

For a service with base_url = https://api.example.com/v1 and a rule with endpoint = /users:

POST https://api.example.com/v1/users
Authorization: Bearer eyJhbGci...
Content-Type: application/json

{"userid": 5, "action": "created"}

Adding an AMQP Service (RabbitMQ)

When Type = AMQP, the form shows a Connection Builder instead of a plain URL field.

Connection Builder Fields

FieldDescriptionDefault
HostRabbitMQ broker hostname or IPlocalhost
Port5672 for plain AMQP, 5671 for AMQPS (SSL)5672
UserRabbitMQ usernameguest
PasswordRabbitMQ passwordguest
Virtual HostRabbitMQ vhost/
ExchangeTarget exchange name. Leave empty for the default exchange(empty)
Routing KeyDefault routing key for published messagesevents.moodle
Queue to DeclareQueue to auto-declare when connecting. Useful for developmentmoodle_events
Dead Letter QueueQueue name for messages that cannot be deliveredmoodle_dlq

The connection URL is built automatically:

amqp://user:password@host:5672/vhost?exchange=X&routing_key=Y&queue_declare=Z&dlq=DLQ

Tip: For production, use amqps:// (port 5671) with SSL enabled on your RabbitMQ broker.

Routing Key Override

When calling the MIH API from PHP or from an Event Bridge rule, the endpoint parameter acts as a routing key override:

// Uses the service's default routing key
\local_integrationhub\mih::request('rabbitmq-prod', '/', $payload);

// Overrides with a specific routing key
\local_integrationhub\mih::request('rabbitmq-prod', 'events.user.created', $payload);

Adding a SOAP Service

FieldDescriptionExample
Base URLThe WSDL URLhttps://legacy.example.com/service?wsdl
TypeSOAPSOAP

When calling via MIH API or Event Bridge, the endpoint field is the SOAP method name:

\local_integrationhub\mih::request('legacy-soap', 'CreateUser', ['name' => 'John', 'email' => '[email protected]']);

Editing and Deleting Services

  • Click the pencil icon on any service row to edit
  • Click the trash icon to delete (requires confirmation)
  • Deleting a service also deletes all associated rules, logs, and circuit breaker state

Managing Rules (Event Bridge)

Adding a Rule

  1. Go to the Rules tab
  2. Click Add Rule

Rule Fields

FieldDescriptionExample
EventFull PHP class name of the Moodle event. Use the autocomplete datalist\core\event\user_created
ServiceTarget service (only enabled services appear)notification-api
HTTP MethodFor REST services: POST, GET, PUT, PATCH, DELETEPOST
EndpointPath appended to the service's base URL (optional). For AMQP: routing key override/webhooks/users
Payload TemplateJSON template with {{variable}} placeholdersSee below
ActiveEnable/disable without deletingchecked

Payload Template Syntax

{
"event": "{{eventname}}",
"user_id": {{userid}},
"object_id": {{objectid}},
"course_id": {{courseid}},
"timestamp": {{timecreated}},
"source": "moodle"
}

Important: Numeric values ({{userid}}, {{objectid}}, etc.) should NOT be wrapped in quotes in the template — they will be replaced with raw integers. String values ({{eventname}}, {{ip}}) should be wrapped in quotes.

Preview Payload

Click Preview Payload to see the interpolated result with mock data before saving the rule.


Common Event Names

EventDescription
\core\event\user_createdA new user account was created
\core\event\user_updatedA user profile was updated
\core\event\user_deletedA user was deleted
\core\event\course_createdA new course was created
\core\event\course_completedA user completed a course
\core\event\user_enrolment_createdA user was enrolled in a course
\core\event\user_enrolment_deletedA user was unenrolled
\core\event\grade_item_updatedA grade was updated
\core\event\user_loggedinA user logged in
\core\event\user_loggedoutA user logged out
\core\event\badge_awardedA badge was awarded to a user
\core\event\message_sentA message was sent

Dashboard Monitoring

The main dashboard (/local/integrationhub/index.php) provides:

Charts

ChartDescription
Status DistributionPie chart showing the ratio of successful vs. failed requests across all services
Latency TrendLine chart showing response times for the last 200 requests

Services Table

Each service row shows:

ColumnDescription
NameService slug
TypeREST / AMQP / SOAP
CircuitCurrent circuit state: CLOSED (green), OPEN (red), HALFOPEN (yellow)
Avg LatencyAverage response time over the last 24 hours
Errors (24h)Number of failed requests in the last 24 hours
Last UsedTimestamp of the most recent request
ActionsEdit, Delete, Reset Circuit

Resetting a Circuit

If a service has recovered but its circuit is still OPEN:

  1. Click Reset Circuit on the service row
  2. The circuit transitions to CLOSED and the failure counter resets

To reset all circuits at once, click Reset All Circuits.


Dead Letter Queue (DLQ)

When an event fails to dispatch after 5 attempts, it is moved to the DLQ.

Navigate to /local/integrationhub/queue.php to:

  • View all failed events with their error messages and payloads
  • Replay individual events (re-queues them as a new adhoc task)
  • Delete events that are no longer needed

When Events End Up in the DLQ

  • The target service is permanently down and the circuit never recovers
  • The payload template produces invalid JSON
  • The service was deleted after the rule was created
  • A network error persists beyond 5 retry attempts

Log Viewer

Navigate to /local/integrationhub/logs.php to view the request log.

The log shows:

  • Timestamp
  • Service name
  • Endpoint called
  • HTTP method
  • HTTP status code
  • Latency (ms)
  • Number of attempts
  • Success/failure status
  • Error message (if failed)

Note: The log is automatically pruned to the configured maximum (default: 500 entries). Older entries are deleted first.