outhebox/laravel-ibmq

This is my package laravel-ibmq

0.1 2024-09-17 12:13 UTC

This package is auto-updated.

Last update: 2024-10-17 12:32:24 UTC


README

Features | Requirements | Installation | Usage | Changelog

Latest Stable Version Tests Total Downloads PHP from Packagist Laravel Version

A Laravel package to connect with IBM MQ, allowing for sending and receiving messages. This package supports multiple queues for inbound and outbound messages, with advanced error handling and logging.

Features

  • Easy-to-use API for interacting with IBM MQ.
  • Separate queues for inbound and outbound messaging.
  • Fluent API for sending and receiving messages.
  • Configurable via environment variables.

Requirements

  • PHP 8.1+ with ext-sockets extension enabled
  • Laravel 10 or higher
  • IBM MQ instance

Installation

You can install the package via composer:

composer require outhebox/laravel-ibmq

You can publish the config file with:

php artisan vendor:publish --tag="laravel-ibmq-config"

This is the contents of the published config file:

return [
    'host' => env('IBM_MQ_HOST', 'your-host'),
    'port' => env('IBM_MQ_PORT', 1414),
    'queue_manager' => env('IBM_MQ_QUEUE_MANAGER', 'your-queue-manager'),
    'username' => env('IBM_MQ_USERNAME', null),
    'password' => env('IBM_MQ_PASSWORD', null),

    'queues' => [
        'inbound' => env('IBM_MQ_INBOUND_QUEUE', 'your-inbound-queue'),
        'outbound' => env('IBM_MQ_OUTBOUND_QUEUE', 'your-outbound-queue'),
    ],
];

Usage

Sending Messages

use Outhebox\LaravelIBMQ\Facades\LaravelIBMQ;
use Outhebox\LaravelIBMQ\Exceptions\IBMQException;

$ibmQueue = new LaravelIBMQ();

try {
    $ibmQueue->sendMessage('Hello, IBM MQ!');
    echo "Message sent successfully!";
} catch (IBMQException $e) {
    echo "Failed to send message: " . $e->getMessage();
}

Listening to Messages

use Outhebox\LaravelIBMQ\Facades\LaravelIBMQ;
use Outhebox\LaravelIBMQ\Exceptions\IBMQException;

$ibmQueue = new LaravelIBMQ();

try {
    $ibmQueue->listenToMessages(function ($messageBody) {
        echo "Received message: " . $messageBody;
    });
} catch (IBMQException $e) {
    echo "Failed to receive messages: " . $e->getMessage();
}

Closing Connections

Connections are automatically closed when the object is destroyed or the application ends. However, you can explicitly close the connection if needed:

use Outhebox\LaravelIBMQ\Facades\LaravelIBMQ;

$ibmQueue = new LaravelIBMQ();

$ibmQueue->close();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.