• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Message Broker and PHP
 

Message Broker and PHP

on

  • 10,912 views

These slides explain the PHP support that has been added to WebSphere Message Broker. This feature allows custom transformation and routing logic to be written in PHP.

These slides explain the PHP support that has been added to WebSphere Message Broker. This feature allows custom transformation and routing logic to be written in PHP.

Statistics

Views

Total Views
10,912
Views on SlideShare
10,894
Embed Views
18

Actions

Likes
1
Downloads
154
Comments
1

4 Embeds 18

http://www.slideshare.net 10
http://www.linkedin.com 4
http://www.projectzero.org 3
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Hello

    Hope you are doing well. Please let me know your availability. And please send me your updated resume ASAP. I would like to talk with you for this position.

    Position : IBM WebSphere Message Broker
    Location : Harrisburg, PA
    Duration : 6 Months +
    Interview Process: Phone and Skype interviews

    Skills:

    Experience using IBM WebSphere Message Broker
    • Message sets with COBOL copybooks and WSDL files
    • ESQL
    • XML concepts

    Proficient with WebSphere MQ
    Knowledge of DB2 and SQL concepts.
    Knowledge of XML
    Ability to perform work which requires a great deal of attention to detail.
    Proficient with OO concepts and how they apply to application design.

    Nice to have Experience:

    Familiar with SOAP Nodes, Http nodes, Files nodes in Broker a significant plus
    Familiar with SOAP and REST messaging concepts.
    Familiar with JMS concepts
    Familiar with SOA and SOA concepts
    Familiar with Mainframe/CICS/Cobol programming concepts
    Familiar with MQ Clustering, MQ Destination Lists.
    Familiar with MQ Broker as an Enterprise Service Bus (ESB)
    Proficient with using UML to communicate application design
    Knowledge of SOAP and web services.
    Familiar with JAVA/J2EE
    Familiar with Design Patterns and the application of Design Patterns using message flows such as Request-Reply, Composite message flows, Publish/Subscribe etc

    Interested consultants please send me your resume to nancy@aikoninc.com
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Message Broker and PHP Message Broker and PHP Presentation Transcript

    • WebSphere Message Broker Support for WebSphere sMash PHP © 2008 IBM Corporation 1 WebSphere Message Broker – Support for sMash PHP
    • Objectives Introduce the new PHP Compute node in WebSphere Message Broker v6.1.0.3 Basic introduction to the PHP language Integration of PHP with the ‘element tree’ How to write PHP scripts to: – transform messages – route and filter messages © 2008 IBM Corporation 2 WebSphere Message Broker – Support for sMash PHP
    • WebSphere Message Broker Core Values Universal Connectivity – Simplify application connectivity to provide a flexible and dynamic structure Routes and Transforms data FROM anywhere TO anywhere – Supports a wide range of protocols MQ, JMS 1.1, HTTP(S), Web Services, File, User Defined – Supports a broad range of data formats Binary (C/COBOL), XML, industry(SWIFT, EDI, HIPPAA…), User defined Simple Programming – Message Flows to describe application connectivity comprising… • Message Nodes which encapsulate required integration logic which operate on… • Message Tree which describes the data in a format independent manner – Transformation options of Graphical mapping, Java, ESQL, PHP, XSL, and WTX Many environments – Wide range of operating systems and hardware platforms supported High Performance © 2008 IBM Corporation 3 WebSphere Message Broker – Support for sMash PHP
    • Broker overview – flows, nodes, message tree Parser Parser invoked Parser invoked associated with (on demand) (in reverse) bit-stream bit-stream tree tree bit-stream Input node reads Node accesses logical Output node writes bit-stream message tree bit-stream Input Transformation Output © 2008 IBM Corporation 4 WebSphere Message Broker – Support for sMash PHP
    • Transformation in Message Broker Graphical Mapping XSLT ESQL Java PHP – Each has particular resonance with different customer skill sets © 2008 IBM Corporation 5 WebSphere Message Broker – Support for sMash PHP
    • PHP PHP is a dynamic scripting language used to implement web sites Easy to use – gentle learning curve Efficient syntax and library have evolved in open source – Community driven to get more done in less time – Impressive results with little code – Extensive library support – Language suited to rapid incremental prototyping http://www.php.net © 2008 IBM Corporation 6 WebSphere Message Broker – Support for sMash PHP
    • Why PHP in Message Broker? More than 3 million developers worldwide Source Gartner 12/2007 Predicted to grow to 5.5M developers Source Gartner 12/2007 – 60% corporate by 2013 4th most popular language (after Java/C/VB) Source TIOBE Programming Community Index PHP installed on 20M+ web domains (34% of internet) Source www.netcraft.com Customer demand for ‘scripting’ support in the broker – Allowing rapid development of message processing logic © 2008 IBM Corporation 7 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute Node overview New general purpose programmable node Embeds the IBM sMash Runtime for PHP – Java implementation, fully compliant with PHP version 5.2 – As used in WebSphere sMash Message tree navigation syntax integrated into PHP language – Inspired by ESQL path navigation and SimpleXML PHP extension API to work with messages and interact with the broker XPath 1.0 support Supports addition of dynamic output terminals for message routing Phased rollout starting with WMB v6.1.0.3 – Starting with Windows © 2008 IBM Corporation 8 WebSphere Message Broker – Support for sMash PHP
    • Node basics Enable new v6.1.0.3 features – mqsichangebroker <brokerName> -f all All PHP code must appear in <?php … ?> code islands – Anything outside this is ignored (in fact, it’s copied to STDOUT) Two PHP script styles are supported – Declare a class with an ‘evaluate()’ method • Gets invoked for each message • Annotations control message copying and routing behaviour – Plain script • No class declaration required • Users have to write more code to support message copying and routing No state is retained by the node between messages – Inherently thread-safe © 2008 IBM Corporation 9 WebSphere Message Broker – Support for sMash PHP
    • A first example – Hello.php <?php class Hello { /** * @MessageBrokerSimpleTransform */ function evaluate ($output, $input) { $output->XMLNSC->doc->greeting = 'Hello'; } } ?> © 2008 IBM Corporation 10 WebSphere Message Broker – Support for sMash PHP
    • A first example – Hello.php <?php class Hello { /** * @MessageBrokerSimpleTransform */ function evaluate ($output, $input) { $output->XMLNSC->doc->greeting = 'Hello'; } } <doc> ?> <greeting>Hello</greeting> </doc> © 2008 IBM Corporation 10 WebSphere Message Broker – Support for sMash PHP
    • The same example, without the class <?php $output_message = new MbsMessage($assembly[MB_MESSAGE]); $output_message->XMLNSC->doc->greeting = 'Hello'; $output_assembly = new MbsMessageAssembly($assembly, $output_message); $output_assembly->propagate('out'); ?> © 2008 IBM Corporation 11 WebSphere Message Broker – Support for sMash PHP
    • Navigating the message tree Each element in the tree is represented by an MbsElement object The element tree can be navigated in two ways: – Path syntax • $output->MRM->bin->item = $input->XMLNSC->doc->ref->item; • Performs deep tree copy from RHS to LHS • Elements on LHS are created if they don’t already exist • Navigation is not namespace-aware – API methods • $value = $items->getFirstChild()->getValue(); • $catalog->addElement('Item', $value); © 2008 IBM Corporation 12 WebSphere Message Broker – Support for sMash PHP
    • Element navigation API MbsElement has methods for traversing the message tree getParent() getPreviousSibling() getNextSibling() MbsElement getFirstChild() getLastChild() Get a child element by name (optional occurrence) – getChild(string $name [, int occurrence]) Get an array of all children (optional namespace) – getChildren([string $namespace]) © 2008 IBM Corporation 13 WebSphere Message Broker – Support for sMash PHP
    • <document> <chapter title=’Introduction’> Navigating the message tree Some text. </chapter> <chapter title=’Beginnings’> More text. N: Root </chapter> V: </document> N: Properties N: MQMD N: XMLNSC V: V: V: N: document V: <document> <chapter title=’Introduction’> Some text. N: chapter N: chapter </chapter> V: Some text. V: More text. <chapter title=’Beginnings’> More text. </chapter> </document> N: title N: title V: Introduction V: Beginnings © 2008 IBM Corporation 14 WebSphere Message Broker – Support for sMash PHP
    • <document> <chapter title=’Introduction’> Navigating the message tree Some text. </chapter> <chapter title=’Beginnings’> More text. N: Root </chapter> V: </document> N: Properties N: MQMD N: XMLNSC V: V: V: N: document V: <document> <chapter title=’Introduction’> Some text. N: chapter N: chapter </chapter> V: Some text. V: More text. <chapter title=’Beginnings’> $xml = $input->getLastChild(); More text. $doc = $xml->getFirstChild(); </chapter> $ch1 = $doc->getFirstChild(); </document> N: title N: title $ch2 = $ch1->getNextSibling() V: Introduction V: Beginnings $attr = $ch2->getFirstChild(); © 2008 IBM Corporation 14 WebSphere Message Broker – Support for sMash PHP
    • <document> <chapter title=’Introduction’> Navigating the message tree Some text. </chapter> <chapter title=’Beginnings’> More text. N: Root </chapter> V: </document> N: Properties N: MQMD N: XMLNSC V: V: V: N: document V: $xml = $input->getChild(‘XMLNSC’); <document> $doc = $xml->getChild(‘document’); <chapter title=’Introduction’> $ch2 Some text. = $doc->getChild(‘chapter’, 1); N: chapter N: chapter </chapter> $attr = $ch2->getAttribute(‘title’); V: Some text. V: More text. <chapter title=’Beginnings’> $xml = $input->getLastChild(); More text. $doc = $xml->getFirstChild(); </chapter> $ch1 = $doc->getFirstChild(); </document> N: title N: title $ch2 = $ch1->getNextSibling() V: Introduction V: Beginnings $attr = $ch2->getFirstChild(); © 2008 IBM Corporation 14 WebSphere Message Broker – Support for sMash PHP
    • <document> <chapter title=’Introduction’> Navigating the message tree Some text. </chapter> <chapter title=’Beginnings’> More text. N: Root </chapter> V: </document> N: Properties N: MQMD N: XMLNSC V: V: V: $attr = $input->XMLNSC->document->chapter[1][‘title’] N: document V: $xml = $input->getChild(‘XMLNSC’); <document> $doc = $xml->getChild(‘document’); <chapter title=’Introduction’> $ch2 Some text. = $doc->getChild(‘chapter’, 1); $attr = $ch2->getAttribute(‘title’); N: chapter N: chapter </chapter> V: Some text. V: More text. <chapter title=’Beginnings’> $xml = $input->getLastChild(); More text. $doc = $xml->getFirstChild(); </chapter> $ch1 = $doc->getFirstChild(); </document> N: title N: title $ch2 = $ch1->getNextSibling() V: Introduction V: Beginnings $attr = $ch2->getFirstChild(); © 2008 IBM Corporation 14 WebSphere Message Broker – Support for sMash PHP
    • Reading the message MbsElement represents a ‘parsed’ logical part of the message Each element has – a name • getName() – returns a string – a value • getValue() – returns an value of parser determined type – a namespace • getNamespace() – returns a string (XML parsers only) – a type • getType() – returns the parser specific type of the element (integer) © 2008 IBM Corporation 15 WebSphere Message Broker – Support for sMash PHP
    • $ PHP Variables Variables start with a ‘$’ – E.g. $name, $name2, $first_name, $firstName Variable names are case sensitive No need to declare a variable – just assign to it – $city = quot;Barcelonaquot;; Variables are evaluated inside “strings” (double quoted) – print quot;Hello, $citynquot;; • Hello, Barcelona …but not ‘strings’ (single quoted) – print 'Hello, $cityn'; • Hello, $cityn © 2008 IBM Corporation 16 WebSphere Message Broker – Support for sMash PHP
    • Variable Types PHP is weakly typed – Variable types are inferred at runtime – The type can change during the evaluation of the script Variable can be one of following types – Integer – Float – String – Boolean – Array – Object – Resource © 2008 IBM Corporation 17 WebSphere Message Broker – Support for sMash PHP
    • Conditional statements if statement case switching – if($city == 'Barcelona') { – switch($city) { print quot;Holanquot;; case 'Barcelona': } elseif($city == 'London') { print quot;Holanquot;; print quot;Hellonquot;; break; } else { case 'London': print quot;Hinquot;; print quot;Hellonquot;; } break; default: print quot;Hinquot;; } © 2008 IBM Corporation 18 WebSphere Message Broker – Support for sMash PHP
    • Looping constructs while – while($total <= 10) { … } do…while – do { … } while($total <= 10); for – for($i = 0; $i < 10; $i++) { … } foreach – Array iteration – more later… © 2008 IBM Corporation 19 WebSphere Message Broker – Support for sMash PHP
    • PHP Arrays PHP provides special syntax for handling arrays An array can be indexed (list) or associative (map) – $list = array('one', 'two', 'three'); – $map = array('one' => 'uno', 'two' => 'dos', 'three' => 'tres'); Array access operator – returns ‘three’ – $list[2] – returns ‘dos’ – $map['two'] Append to an array – $list[] = 'four'; – $map['four'] = 'cuatro'; © 2008 IBM Corporation 20 WebSphere Message Broker – Support for sMash PHP
    • Array iteration foreach statement – For iterating over an array – foreach($array as $value) { print quot;$valuenquot;; } – foreach($array as $key => $value) { print quot;$key: $valuenquot;; } © 2008 IBM Corporation 21 WebSphere Message Broker – Support for sMash PHP
    • MbsElement – repeating structures MbsElement supports the array operator ‘[]’ to access repeating elements – $second = $input->XMLNSC->doc->item[1]; It also supports the creation of repeating elements – $output->XMLNSC->doc->item[] = 'foo'; – This creates the ‘XMLNSC’ and ‘doc’ folders, if they don’t exist – It creates a new ‘item’ element regardless of whether one already exists Can iterate over a repeating element – foreach($input->XMLNSC->doc->item as $item) { print $item; } © 2008 IBM Corporation 22 WebSphere Message Broker – Support for sMash PHP
    • PHP arrays and the element tree An array can be used to create a repeating structure – $list = array('uno', 'dos', 'tres'); $output->XMLNSC->doc->number[] = $list; – <doc> <number>uno</number> <number>dos</number> <number>tres</number> </doc> © 2008 IBM Corporation 23 WebSphere Message Broker – Support for sMash PHP
    • Populating an element tree from an array An array can be used to create a repeating structure – $map = array('one' => 'uno', 'two' => 'dos', 'three' => 'tres'); $output->XMLNSC->doc->numbers = $map; – <doc> <numbers> <one>uno</one> <two>dos</two> <three>tres</three> </numbers> </doc> © 2008 IBM Corporation 24 WebSphere Message Broker – Support for sMash PHP
    • Spot the difference $map = array('one' => 'uno', 'two' => 'dos', 'three' => 'tres'); ...->doc->numbers[] = $map; – <doc> <numbers>uno</numbers> <numbers>dos</numbers> <numbers>tres</numbers> </doc> © 2008 IBM Corporation 25 WebSphere Message Broker – Support for sMash PHP
    • Spot the difference $map = array('one' => 'uno', 'two' => 'dos', 'three' => 'tres'); ...->doc->numbers = $map; ...->doc->numbers[] = $map; – <doc> – <doc> <numbers> <numbers>uno</numbers> <one>uno</one> <numbers>dos</numbers> <two>dos</two> <numbers>tres</numbers> </doc> <three>tres</three> </numbers> </doc> © 2008 IBM Corporation 25 WebSphere Message Broker – Support for sMash PHP
    • Spot the difference $map = array('one' => 'uno', 'two' => 'dos', 'three' => 'tres'); ...->doc->numbers = $map; ...->doc->numbers[] = $map; – <doc> – <doc> <numbers> <numbers>uno</numbers> <one>uno</one> <numbers>dos</numbers> <two>dos</two> <numbers>tres</numbers> </doc> <three>tres</three> </numbers> </doc> © 2008 IBM Corporation 25 WebSphere Message Broker – Support for sMash PHP
    • Nested arrays Array values can be arrays themselves Can be used to build complex structures $output_root->XMLNSC->doc->items = array('book' => array('title' => 'PHP in a Nutshell', 'author' => 'Paul Hudson'), 'fruit' => 'apple', 'dog' => array('breed' => 'Spaniel', 'ears' => 'long') ); © 2008 IBM Corporation 26 WebSphere Message Broker – Support for sMash PHP
    • Nested arrays Array values can be arrays themselves Can be used to build complex structures $output_root->XMLNSC->doc->items = <doc> array('book' => array('title' => 'PHP in a Nutshell', <items> 'author' => 'Paul Hudson'), <book> <title>PHP in a 'apple', 'fruit' => Nutshell</title> <author>Paul => array('breed' => 'dog' 'Spaniel', Hudson</author> 'ears' => 'long') ); </book> <fruit>apple</fruit> <dog> <breed>Spaniel</breed> <ears>long</ears> </dog> </items> </doc> © 2008 IBM Corporation 26 WebSphere Message Broker – Support for sMash PHP
    • Support for XML attributes XML attributes behave as map arrays on an element – $attr = $input->XMLNSC->doc->folder['name'] – Returns the ‘name’ attribute of the ‘folder’ element Attributes can be created in a similar way – $output->XMLNSC->doc->folder['name'] = 'PHP'; – <doc> <folder name=‘PHP’/> </doc> © 2008 IBM Corporation 27 WebSphere Message Broker – Support for sMash PHP
    • Functions Functions are defined as follows… – function myFunction() { ... } Parameters can be passed in, and values returned – function square($number) { return $number * $number; } $sixteen = square(4); © 2008 IBM Corporation 28 WebSphere Message Broker – Support for sMash PHP
    • Functions returning MbsElement When writing message transformation code, use functions to break down the problem and transform sub-trees… – function transformItem($inItem) { $outItem = new MbsElement; $outItem->description = $inItem->desc; return $outItem; } – foreach($input->XMLNSC->doc->item as $item) { $output->XMLNSC->folder->part[] = transformItem($item); } © 2008 IBM Corporation 29 WebSphere Message Broker – Support for sMash PHP
    • Classes and methods PHP 5 introduced full object-oriented support into the language – class ItemTransformer { private $total = 0; private $prefix = 'wmb_'; public function transform ($inItem) { $outItem = new MbsElement; $outItem->description = $this->prefix . $inItem->desc->getValue(); $this->total += $inItem->quantity->getValue(); return $outItem; } } – $transformer = new ItemTransformer; $output->XMLNSC->folder->item = $transformer->transform($item); © 2008 IBM Corporation 30 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute node class The PHP Compute node supports the use of a class definition to contain message processing logic Create a class with name matching the name of the script (without the .php extension) Create a method called ‘evaluate’ – Declare 2 parameters; the first will refer to the output message assembly, the second will refer to the input message assembly • The names of these parameters is your choice • The second (input) parameter is optional Choose an appropriate ‘annotation’ on the method – More on this later… Implement the node logic © 2008 IBM Corporation 31 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute node class <?php class MyNode { /** * @MessageBrokerSimpleTransform */ function evaluate ($output, $input) { $output->XMLNSC->doc->part = $this->transform($output->MRM->folder->item); } function transform ($item) { $element = new MbsElement; $element->name = $item->id; return $element; } } ?> © 2008 IBM Corporation 32 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute node class Don’t forget the <?php <?php … ?> tag!! class MyNode { /** * @MessageBrokerSimpleTransform */ function evaluate ($output, $input) { $output->XMLNSC->doc->part = $this->transform($output->MRM->folder->item); } function transform ($item) { $element = new MbsElement; $element->name = $item->id; return $element; } } ?> © 2008 IBM Corporation 32 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute node class Don’t forget the <?php <?php … ?> tag!! The script filename class MyNode { must be MyNode.php /** * @MessageBrokerSimpleTransform */ function evaluate ($output, $input) { $output->XMLNSC->doc->part = $this->transform($output->MRM->folder->item); } function transform ($item) { $element = new MbsElement; $element->name = $item->id; return $element; } } ?> © 2008 IBM Corporation 32 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute node class Don’t forget the <?php <?php … ?> tag!! The script filename class MyNode { must be MyNode.php /** * @MessageBrokerSimpleTransform Define an ‘evaluate’ */ method function evaluate ($output, $input) { $output->XMLNSC->doc->part = $this->transform($output->MRM->folder->item); } function transform ($item) { $element = new MbsElement; $element->name = $item->id; return $element; } } ?> © 2008 IBM Corporation 32 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute node class Don’t forget the <?php <?php … ?> tag!! The script filename class MyNode { must be MyNode.php /** * @MessageBrokerSimpleTransform Define an Declare the message ‘evaluate’ */ assembly parameters method function evaluate ($output, $input) { $output->XMLNSC->doc->part = $this->transform($output->MRM->folder->item); } function transform ($item) { $element = new MbsElement; $element->name = $item->id; return $element; } } ?> © 2008 IBM Corporation 32 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute node class Create a ‘doc comment’ Don’t forget the <?php block and select <?php … ?> tag!! annotation(s) The script filename class MyNode { must be MyNode.php /** * @MessageBrokerSimpleTransform Define an Declare the message ‘evaluate’ */ assembly parameters method function evaluate ($output, $input) { $output->XMLNSC->doc->part = $this->transform($output->MRM->folder->item); } function transform ($item) { $element = new MbsElement; $element->name = $item->id; return $element; } } ?> © 2008 IBM Corporation 32 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute node class Create a ‘doc comment’ Don’t forget the <?php block and select <?php … ?> tag!! annotation(s) The script filename class MyNode { must be MyNode.php /** * @MessageBrokerSimpleTransform Define an Declare the message ‘evaluate’ */ assembly parameters method function evaluate ($output, $input) { $output->XMLNSC->doc->part = $this->transform($output->MRM->folder->item); } Implement node logic function transform ($item) { $element = new MbsElement; $element->name = $item->id; return $element; } } ?> © 2008 IBM Corporation 32 WebSphere Message Broker – Support for sMash PHP
    • PHP Compute node class Create a ‘doc comment’ Don’t forget the <?php block and select <?php … ?> tag!! annotation(s) The script filename class MyNode { must be MyNode.php /** * @MessageBrokerSimpleTransform Define an Declare the message ‘evaluate’ */ assembly parameters method function evaluate ($output, $input) { $output->XMLNSC->doc->part = $this->transform($output->MRM->folder->item); } Implement node logic function transform ($item) { $element = new MbsElement; This can include calling $element->name = $item->id; user-defined functions return $element; } } ?> © 2008 IBM Corporation 32 WebSphere Message Broker – Support for sMash PHP
    • Annotations Annotations control the context in which the evaluate method is called They specify message transformation options – New empty output message for general transformation – Copy of the input message for modification – Copy of the local environment They can also specify the message routing behaviour – Which output terminal to propagate to Annotations reduce the amount of boilerplate code that would otherwise need to be written by the user Annotations can be combined © 2008 IBM Corporation 33 WebSphere Message Broker – Support for sMash PHP
    • Message transformation The input message and message assembly are read-only New objects must be created to build a new (transformed) message – In the case of the message assembly, the new object must encapsulate the new output message and the other (environment) trees from the input message assembly Good news: an annotation does this for you – @MessageBrokerSimpleTransform – Specified in Doc Comment on evaluate method – New message (assembly) – 1st parameter – Original (input) message – 2nd parameter © 2008 IBM Corporation 34 WebSphere Message Broker – Support for sMash PHP
    • Modifying a message If you wish to modify the input message rather than populate an empty one, a copy of the input message can be created Annotation available to do this – @MessageBrokerCopyTransform – Output (copied) message – 1st parameter – Original (input) message – 2nd parameter • This 2nd parameter is always optional © 2008 IBM Corporation 35 WebSphere Message Broker – Support for sMash PHP
    • Modifying the Local Environment The Local Environment is another logical tree in the message assembly – Scratchpad for information about the message, but not part of the message – Populated by many IBM nodes, but can also be modified by the user Good practice (but not enforced) to make a copy before modifying – Annotation available to do this – @MessageBrokerLocalEnvironmentTransform – The output message assembly (1st parameter) will contain a copy of this tree © 2008 IBM Corporation 36 WebSphere Message Broker – Support for sMash PHP
    • Message Assembly The Message Assembly contains four objects – Message – the ‘business data’ – Local Environment – node and message metadata – Global Environment – general scratchpad – Exception List – used for ‘failure’ processing; contains error info In PHP, these objects can be accessed using array notation – $input[MB_MESSAGE] – same as $input without subscript – $input[MB_LOCAL_ENVIRONMENT] – $input[MB_GLOBAL_ENVIRONMENT] – $input[MB_EXCEPTION_LIST] © 2008 IBM Corporation 37 WebSphere Message Broker – Support for sMash PHP
    • Local Environment example /** * @MessageBrokerCopyTransform * @MessageBrokerLocalEnvironmentTransform */ function evaluate($output, $input) { $output->XMLNSC->doc->filename = $input[MB_LOCAL_ENVIRONMENT]->File->Name; foreach($input->XMLNSC->doc->MQdest->queue as $queue) { $output[MB_LOCAL_ENVIRONMENT]->Destination->MQ-> DestinationData[]->queueName = $queue; } } © 2008 IBM Corporation 38 WebSphere Message Broker – Support for sMash PHP
    • Message routing and filtering By default, the output message assembly is propagated to the ‘out’ terminal after the ‘evaluate’ method has been processed Users can create new ‘dynamic’ output terminals Message must be explicitly propagated to these terminals Again, an annotation can help – @MessageBrokerRouter – Terminal name specified by string return value of evaluate method – If no string is returned, message doesn’t get propagated – Alternatively, call ‘propagate’ method on assembly object • Pass terminal name as parameter • Useful for multiple propagates, e.g. message shredding © 2008 IBM Corporation 39 WebSphere Message Broker – Support for sMash PHP
    • Routing example /** * @MessageBrokerRouter */ function evaluate($message) { if ($message->XMLNSC->doc->threshold->getValue() > 10) { return 'out'; } else { return 'other'; } } © 2008 IBM Corporation 40 WebSphere Message Broker – Support for sMash PHP
    • Another example – message shredding /** * @MessageBrokerSimpleTransform * @MessageBrokerRouter */ function evaluate($output, $input) { foreach ($input->LargeDoc->Part as $part) { $output->XMLNSC->SmallDoc = $part; $output->propagate('out'); } } © 2008 IBM Corporation 41 WebSphere Message Broker – Support for sMash PHP
    • Route-to-label Can propagate a message assembly directly to a ‘Label’ node. Alternative form of message routing. – No need to propagate to output terminal(s). – No need for ‘RouteToLabel’ node. … $output->routeToLabel('label2'); © 2008 IBM Corporation 42 WebSphere Message Broker – Support for sMash PHP
    • XPath 1.0 - Overview XPath is a language for addressing parts of a document Operates on the logical tree Location Paths – Used to navigate the tree – Series of location steps separated by ‘/’ – Each step selects a set of nodes relative to the previous step Expressions – Function library – Numeric and Boolean operators – Variable references W3C recommendation http://www.w3.org/TR/xpath © 2008 IBM Corporation 43 WebSphere Message Broker – Support for sMash PHP
    • Location Paths Abbreviated and unabbreviated syntax – /document is an abbreviation of /child::document Relative and absolute location paths – Leading ‘/’ means start from message body Location step comprises – Axis – specifies ‘how’ to search for a named node (default is child) – NodeTest – specifies the name or type of node – namespace aware – Predicates - expressions to filter the set of matching nodes (optional) • Appear in square brackets [ ] after the NodeTest © 2008 IBM Corporation 44 WebSphere Message Broker – Support for sMash PHP
    • XPath example //book[@price < 10]/title <bookshop> <stock> <book price=‘49.99’> <title>Learn WebSphere in 24 hours</title> </book> <book price=‘9.99’> <title>Unix in a Nutshell</title> </book> <book price=‘4.50’> <title>XPath quick reference</title> </book> </stock> </bookshop> © 2008 IBM Corporation 45 WebSphere Message Broker – Support for sMash PHP
    • XPath example //book[@price < 10]/title <bookshop> <stock> <book price=‘49.99’> <title>Learn WebSphere in 24 hours</title> </book> <book price=‘9.99’> <title>Unix in a Nutshell</title> </book> <book price=‘4.50’> <title>XPath quick reference</title> </book> </stock> </bookshop> © 2008 IBM Corporation 46 WebSphere Message Broker – Support for sMash PHP
    • XPath example //book[@price < 10]/title <bookshop> <stock> <book price=‘49.99’> <title>Learn WebSphere in 24 hours</title> </book> <book price=‘9.99’> <title>Unix in a Nutshell</title> </book> <book price=‘4.50’> <title>XPath quick reference</title> </book> </stock> </bookshop> © 2008 IBM Corporation 47 WebSphere Message Broker – Support for sMash PHP
    • XPath example //book[@price < 10]/title <bookshop> <stock> <book price=‘49.99’> <title>Learn WebSphere in 24 hours</title> </book> <book price=‘9.99’> <title>Unix in a Nutshell</title> </book> <book price=‘4.50’> <title>XPath quick reference</title> </book> </stock> </bookshop> © 2008 IBM Corporation 48 WebSphere Message Broker – Support for sMash PHP
    • Expressions Expressions can operate on and return four basic types – Node sets • unions, filters, location paths – Booleans • and, or, =, !=, <, <=, >, >= – Numbers • +, -, *, div, mod, sum() – Strings • functions including concat(), substring(), contains() … © 2008 IBM Corporation 49 WebSphere Message Broker – Support for sMash PHP
    • Calling XPath from PHP Simple method call on message or element – $msg->xpath('//book[@price < 10]'); – Returns an array of MbsElement objects For namespaced elements, pass an array of namespace mappings (prefix => namespace URI) – $ns = array('ibm' => 'http://www.ibm.com/my-uri'); $msg->xpath('//ibm:book[@price < 10]', $ns); © 2008 IBM Corporation 50 WebSphere Message Broker – Support for sMash PHP
    • XPath to PHP types xpath() function returns one of following PHP types – Boolean – Float – String – Array • This is an array of MbsElement objects • Can be iterated over… – foreach($msg->xpath('//book[@price < 10]') as $book) { … • Or assigned into another tree… – $output->XMLNSC->doc->book[] = $msg->xpath('… © 2008 IBM Corporation 51 WebSphere Message Broker – Support for sMash PHP
    • User-defined properties Defined in the tooling – ‘User Defined Properties’ tab of message flow editor – Values set in Message Flow properties dialog Accessed in PHP – mb_get_user_defined_property('name') function – Read only – Returns object of appropriate type • Depends on definition in the tooling © 2008 IBM Corporation 52 WebSphere Message Broker – Support for sMash PHP
    • Java Bridge The IBM sMash Runtime for PHP has the ability to instantiate Java classes and invoke their methods Can be used to manipulate values in an MRM or XMLNSC tree with xsd types that do not map directly to PHP types – xsd:decimal type java.math.BigDecimal – xsd:dateTime com.ibm.broker.plugin.MbTimestamp Tutorial on IBM developerWorks website – Integrating Java and PHP in WebSphere sMash • http://www.ibm.com/developerworks/websphere/library/techarticles/0809_phillips/0809_phillips.html © 2008 IBM Corporation 53 WebSphere Message Broker – Support for sMash PHP
    • Java Bridge example /** * @MessageBrokerSimpleTransform */ function evaluate ($output, $input) { $number = $input->XMLNSC->doc->number->getValue(); $signature = new JavaSignature (JAVA_STRING); $decimal = new Java(quot;java.math.BigDecimalquot;, $signature, quot;654.321quot;); $sum = $number->add($decimal); $output->XMLNSC->doc->number = $sum; $timestamp = $input->XMLNSC->doc->date->getValue(); $now = new Java(quot;java.util.Datequot;); $timestamp->setTime($now); $output->XMLNSC->doc->date = $timestamp; } © 2008 IBM Corporation 54 WebSphere Message Broker – Support for sMash PHP
    • Debugging Print variables to stdout/stderr – Output written to <WorkPath>components<brokerName><egUUID>console.txt Download the Eclipse PHP Development Toolkit (PDT) – Not supported in current release – Requires Eclipse v3.3 or later – http://www.eclipse.org/pdt/ – Can attach PDT debugger to Broker • Set breakpoints • Examine variables © 2008 IBM Corporation 55 WebSphere Message Broker – Support for sMash PHP
    • Summary Use of the node Introduction to PHP Path syntax to navigate messages PHP arrays and repeating elements Transformation and routing XPath 1.0 integration © 2008 IBM Corporation 56 WebSphere Message Broker – Support for sMash PHP