__construct()"HREF="function.samconnection-constructor.html"> Manuál PHP Předcházející Další (no version infor..."/>
Forum und email
SAMConnection->connect()

SAMConnection->connect()

(no version information, might be only in CVS)

SAMConnection->connect() --  Establishes a connection to a Messaging Server

Popis

class SAMConnection {

bool connect ( string protocol [, array properties] )

}

Calling the "connect" method on a SAMConnection object connects the PHP script to a messaging server. No messages can be sent or received until a connection is made.

Seznam parametrů

protocol

A structured string identifying the protocol to be used when attempting to connect to the messaging server. The supported protocols are represented by constants which are normally used but if required the string may be composed dynamically by the script. The string is made up of 2 parts, the first being the protocol identifier and the second a protocol option. The two parts are seperated by a colon (:) character. Acceptable values are described by the following table:

Protocol stringConstantUsage
mqttSAM_MQTTUse the MQTT (MQ Telemetry Transport) protocol connecting as a client to a server.
wmqSAM_WMQUse the IBM MQSeries protocol connecting as a client to a remote messaging server. This is equivalent to "wmq:client" (SAM_WMQ_CLIENT). At least a broker name (SAM_BROKER) must be specified in the options array.
wmq:clientSAM_WMQ_CLIENTUse the IBM MQSeries protocol connecting as a client to a remote messaging server. At least a broker name (SAM_BROKER) must be specified in the options array.
wmq:bindingsSAM_WMQ_BINDINGSUse the IBM MQSeries protocol connecting to a local messaging server and communicating via shared memory. At least a broker name (SAM_BROKER) must be specified in the options array.
wpmSAM_WPMUse the IBM WebSphere Platform Messaging protocol to connect to the messaging infrastructure of a WebSphere Application server or cluster. A bus name must be specified in the options array (SAM_BUS) and endpoint and target chain may also be specified.
rttSAM_RTTUse the IBM Realtime transport protocol to connect to the messaging infrastructure.

properties

An optional associative array of properties to describe the details of the connection required. The following table lists the available property names and accepted values:

Property namedefaultUsage
SAM_BROKERnone The name of the broker or queue manager running on the messaging server.

This property must be set if using one of the variants of the WebSphere MQSeries protocol (SAM_WMQ, SAM_WMQ_CLIENT, SAM_WMQ_BINDINGS).

SAM_HOSTlocalhost The hostname of the machine on which the messaging server is running.
SAM_PORT1414 for SAM_WMQ, 1506 for SAM_WPM, or 1883 for SAM_MQTT The port number on which to attempt communication with the messaging server.
SAM_EXPIRE_AFTER0 Time in milliseconds after which a message is deemed to have expired and can be deleted from queues. The default value is 0 indicating the message never expires.

Warning: Not yet implemented!

SAM_MESSAGE_PERSISTENCEnone Selects whether messages are made persistent during delivery. The value may be SAM_PERSISTENT or SAM_NON_PERSISTENT. The default is dependant on the connection type and capabilities of the Messaging Server to which the connection is made.

Warning: Not yet implemented!

SAM_MQTT_CLEANSTARTFALSE Optional connect option to indicate to an MQTT server that all previous connection data for this client should be removed and that subscriptions should be deleted when the client disconnects explicitly or unexpectedly. Setting the value to TRUE causes SAM to discard any subscription already in place for the client when it connects and also to discard subscription when the client disconnects. Setting the option to FALSE, or using the default, allows subscriptions to be durable and survive across client disconnects.
SAM_PASSWORDnone The password to be used when the Messaging Server to which the connection is being made requires authentication.
SAM_TRANSACTIONSSAM_AUTO Indicates how transactions are handled on this connection. The value may be SAM_AUTO (the default) to allow automatic handling on a per operation basis or SAM_MANUAL to allow the PHP script to control the transaction boundaries. If SAM_MANUAL is used any in-flight transactions will be rolled back if the script is terminated or the connection is closed without a commit being executed.
SAM_USERIDnone The user id to be used when the Messaging Server to which the connection is being made requires authentication.
SAM_WPM_DUR_SUB_HOMEnone The name of the messaging engine where durable subscriptions are managed. (WPM ONLY).

Návratové hodnoty

This method returns FALSE if an error occurs.

Příklady

Příklad 1. Creating a connection to a Messaging Server using the IBM MQSeries protocol (WMQ)

<?php

$conn
->connect(SAM_WMQ, array(SAM_HOST => 'Myhost.myco.com', SAM_PORT => 1506, SAM_BROKER => 'MyBroker'));

?>

Příklad 2. Creating a connection with application transaction control and default host and port values

<?php

$conn
->connect(SAM_WMQ, array(SAM_BROKER => 'MyBroker', SAM_TRANSACTIONS => SAM_MANUAL));

?>

Příklad 3. Creating a connection to a Messaging Server using the IBM WebSphere Platform Messaging protocol (WPM)

<?php

$conn
->connect(SAM_WPM, array(SAM_ENDPOINTS => 'localhost:7278:BootstrapBasicMessaging',
                              
SAM_BUS => 'Bus1', SAM_TARGETCHAIN => 'InboundBasicMessaging'));

?>