Code Monkey home page Code Monkey logo

mqseries-php's Introduction

mqseries-php

client to WebSphere MQ Queue Manager using the PHP mqseries pecl extension for Laravel. This is a fork of https://github.com/amabnl/php-mqseries

How

Installation

Issue following command in console:

composer require bariton3/mqseries-php

Alternatively edit composer.json by adding following line and run composer update

"require": { 
		....,
		"bariton3/mqseries-php",
	
	},

Configuration

Register package service provider and facade in 'config/app.php'

'providers' => [
    ...
    MqSeries\ServiceProvider\MqSeriesServiceProvider::class,
]

'aliases' => [
    ...
    'MqSeries' => MqSeries\Facades\MqSeriesFacade::class,
]

Publish configuration file using php artisan vendor:publish --tag=mqseries --force or simply copy package configuration file and paste into config/mqseries.php

Open configuration file config/mqseries.php and add your service key

    /*
    |----------------------------------
    | Service Keys
    |------------------------------------
    */
    
    'channel' => 'ADD MQ_SERIES_CHANNEL HERE',
    'queue_name' => ' ADD MQ_SERIES_QUEUE_NAME HERE',
    'queue_manager' => 'ADD MQ_SERIES_QUEUE_MANAGER HERE',
    'ip' => ' ADD MQ_SERIES_IP HERE',
    'port' => 'ADD MQ_SERIES_PORT HERE',
    'options' => MQSERIES_MQCNO_STANDARD_BINDING,

If you like to use different keys for any of the services, you can overwrite master API Key by specifying it in the service array for selected web service.

Usage

	//Open Queue:
	$openParams = new MqSeries\Open\Params();
	$openParams->objectDescType = MQSERIES_MQOT_Q;
	$openParams->objectName = config('mqseries.queue_name');
	$openParams->objectQMName  = '';
	$openParams->option = MQSERIES_MQOO_OUTPUT | MQSERIES_MQOO_INPUT_AS_Q_DEF | MQSERIES_MQOO_FAIL_IF_QUIESCING;
	
	try {
		$queueOpenResult = MqSeries::openQueueOnQM($openParams);
	} catch (MqSeries\QueueManagerConnectionFailedException $ex) {
		die('Exception when opening queue: ' . $ex->getCode() . ' - ' . $ex->getMessage());
	} catch (ExtensionNotLoadedException $ex) {
		die('YOU MUST FIRST ENABLE THE mqseries PHP EXTENSION');
	} catch (NoConnectionParametersException $ex) {
		die('YOU DID NOT PROVIDE CONNECTX PARAMS!');
	}
	
	
	if ($queueOpenResult !== true) {
	die(
	    'SOMETHING WENT WRONG WHEN OPENING THE QUEUE: ' .
	    sprintf(
	        "CompCode:%d Reason:%d Text:%s\n",
	        MqSeries::getLastCompletionCode(),
	        MqSeries::getLastCompletionReasonCode(),
	        MqSeries::getLastCompletionReason()
	    )
	);
	}
	
	// put the message on the queue.
	$mqPutParams = new MqSeries\Put\Params();
	$mqPutParams->gmoOptions = MQSERIES_MQPMO_NEW_MSG_ID;
	
	MqSeries::putMessageToQueue($mqPutParams, 'PING');
	
	if (MqSeries::getLastCompletionCode() !== MQSERIES_MQCC_OK) {
		die(printf("put CompCode:%d Reason:%d Text:%s<br>\n", MqSeries::getLastCompletionCode(), MqSeries::etLastCompletionReasonCode(), MqSeries::getLastCompletionReason()));
	}
	
	
	//Get one message from queue:
        $messageContent = '';
        $mqGetParams = new MqSeries\Get\Params();
        $mqGetParams->gmoOptions = MQSERIES_MQGMO_FAIL_IF_QUIESCING | MQSERIES_MQGMO_WAIT | MQSERIES_MQGMO_CONVERT;
        $mqGetParams->gmoWaitInterval = 5000;

        try {
            $messageContent = MqSeries::getMessageFromQueue($mqGetParams);
            echo $messageContent."\n";
        }
        catch (QueueIsEmptyException $ex) {
            echo "The queue is empty, no big deal.";

            if (is_string($messageContent)) {
                echo 'message retrieved from queue: ' . $messageContent;
            } else {
                die(
                    'SOMETHING WENT WRONG WHEN RETRIEVING A MESSAGE: ' .
                    sprintf(
                        "CompCode:%d Reason:%d Text:%s\n",
                        MqSeries::getLastCompletionCode(),
                        MqSeries::getLastCompletionReasonCode(),
                        MqSeries::getLastCompletionReason()
                    )
                );
            }
        }

        //Close & disconnect:
        MqSeries::close();
        MqSeries::disconnect();

mqseries-php's People

Contributors

atatarchuk avatar bariton3 avatar cedroux avatar welcomattic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mqseries-php's Issues

Any documentation?

Do you plan to write any piece of documentation with MqSeries facade available methods?

Thanks for the package ๐Ÿ˜‰

License

Hi,

This library is obviously a copy of my library https://github.com/amabnl/php-mqseries, but for some reason you didn't fork it.

I've open sourced my library under the Apache2 license, which means copyright remains with us. I don't think you're allowed to redistribute it under the MIT license just like that.

Can you please change the license to Apache2 and attribute copyright to Amadeus benelux in your docs?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.