ComposantsComponents

ComposantsComponents › ESB › Route

tRouteOutput

tRouteOutput

ESB › Route

Renvoie des données à la route qui a appelé le job. Chaque colonne de la ligne reçue est écrite dans le message de la route, selon le type choisi : comme corps, comme en-tête, comme propriété de l'échange, ou comme propriété système de la machine Java. Au retour du cTalendJob, la route continue avec le message ainsi modifié. Le job doit commencer par un tRouteInput. Sends data back to the route that called the job. Each column of the received row is written into the message of the route, according to the chosen type: as the body, as a header, as an exchange property, or as a system property of the Java machine. When the cTalendJob returns, the route goes on with the message thus modified. The job must start with a tRouteInput.

EntréeInput

Un lien Main, obligatoire : sans lui, le composant n'écrit rien. One Main link, required: without it, the component writes nothing.

SortieOutput

Aucune Il termine son flux. None It ends its flow.

DéclencheursTriggers

Aucun Ni en entrée ni en sortie : le composant ne déclare que le lien Main. None Neither incoming nor outgoing: the component only declares the Main link.

UtilisationUsage

Répondre dans le même fluxReply in the same flow

row1 (Main) row2 (Main) tRouteInput_1 tMap_1 tRouteOutput_1

Le cas courant : la ligne lue par le tRouteInput est transformée, et le résultat repart vers la route. Une colonne devient le nouveau corps, les autres des en-têtes que la route pourra tester (cMessageRouter) ou transmettre. The common case: the row read by the tRouteInput is transformed, and the result goes back to the route. One column becomes the new body, the others headers that the route can test (cMessageRouter) or pass on.

Répondre depuis un autre sous-jobReply from another subjob

row1 (Main) OnSubjobOk row2 (Main) tRouteInput_1 tDBOutput_1 tDBInput_1 tRouteOutput_1

Le tRouteOutput n'a pas à être dans le sous-job du tRouteInput : placé dans un sous-job lancé ensuite par un déclencheur, il écrit dans le même message. The tRouteOutput does not have to be in the subjob of the tRouteInput: placed in a subjob started afterwards by a trigger, it writes into the same message.

  1. Dans un job qui a un tRouteInput, déposez le tRouteOutput depuis la famille ESB › Route de la palette. In a job that has a tRouteInput, drop the tRouteOutput from the ESB › Route family of the palette.
  2. Reliez-lui la sortie Main du composant précédent : son schéma, vide au départ, prend celui du lien. Connect the Main output of the previous component to it: its schema, empty at first, takes that of the link.
  3. Dans la table Camel, choisissez pour chaque colonne son Type : Corps pour une seule, En-tête, Propriété ou Système pour les autres, avec leur Nom entre guillemets. In the Camel table, choose for each column its Type: Body for a single one, Header, Property or System for the others, with their Name in quotes.
  4. Exécutez la route qui appelle le job, pas le job seul. Run the route that calls the job, not the job alone.

Paramètres simplesBasic settings

Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Le composant n'a ni paramètres avancés ni variables globales. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. The component has no advanced settings and no global variables.

ParamètreSetting DéfautDefault VisibleShown Description
Schéma de sortieOutput SchemaINPUT_SCHEMA VideEmpty ToujoursAlways Les colonnes de la ligne reçue, reprises du lien entrant. Chacune est une donnée à renvoyer à la route. The columns of the received row, taken from the incoming link. Each one is a value to send back to the route.
CamelVALUES Une ligne par colonneOne row per column ToujoursAlways Table calquée sur le schéma : une ligne par colonne, à compléter par les deux réglages ci-dessous. Table modelled on the schema: one row per column, to complete with the two settings below.
TypeVALUES › TYPE En-têteHeader ToujoursAlways Où va la valeur de la colonne : En-tête (Header), Corps (Body), Propriété (Property) ou Système (System). Voir Les quatre types. Where the value of the column goes: Header, Body, Property or System. See The four types.
NomNameVALUES › VALUE VideEmpty Toujours ; en lecture seule pour le type CorpsAlways; read-only for the Body type Le nom de l'en-tête, de la propriété ou de la propriété système : une expression Java, donc un texte entre guillemets ("status"). Obligatoire pour ces trois types, ignoré pour le type Corps, comme le rappelle la note sous la table : The "Name" with "Body" type will be ignored. The name of the header, of the property or of the system property: a Java expression, hence a text in quotes ("status"). Required for these three types, ignored for the Body type, as the note under the table recalls: The "Name" with "Body" type will be ignored.

Les quatre typesThe four types

Le composant écrit dans le message que la route lui a confié, sans le remplacer : ce qu'il ne touche pas reste en place. The component writes into the message the route handed over, without replacing it: what it does not touch stays in place.

Type Ce qui est écritWhat is written Lu dans la route parRead in the route with
CorpsBody Le corps du message, dans le type Java de la colonne. Une colonne Document est écrite en XML et arrive dans la route comme un document DOM (org.w3c.dom.Document).The body of the message, in the Java type of the column. A Document column is written as XML and reaches the route as a DOM document (org.w3c.dom.Document). ${body}, exchange.getIn().getBody()
En-têteHeader Un en-tête du message, créé ou remplacé. La valeur garde son type Java : une colonne Integer donne un en-tête Integer. Les autres en-têtes du message sont conservés.A header of the message, created or replaced. The value keeps its Java type: an Integer column gives an Integer header. The other headers of the message are kept. ${header.total}, exchange.getIn().getHeader("total")
PropriétéProperty Une propriété de l'échange : elle accompagne le message dans la route mais ne part pas avec lui vers l'extérieur.A property of the exchange: it goes along with the message inside the route but does not leave with it. ${exchangeProperty.audit}, exchange.getProperty("audit")
SystèmeSystem Une propriété système de la machine Java (System.setProperty), la valeur convertie en texte. Elle est commune à toutes les routes et à tous les jobs de cette machine, et y reste après le message.A system property of the Java machine (System.setProperty), the value converted to text. It is shared by all the routes and all the jobs of that machine, and stays there after the message. ${sys.demo.last.order}, System.getProperty("demo.last.order")

Une écriture par ligne reçueOne write per received row

Le composant écrit à chaque ligne qui lui arrive, et chaque écriture remplace la précédente. Un job appelé par une route traite un message à la fois : son flux n'a normalement qu'une ligne. S'il en a plusieurs, la route ne voit que la dernière (voir l'exemple « Trois lignes »). The component writes for each row that reaches it, and each write replaces the previous one. A job called by a route handles one message at a time: its flow normally has a single row. If it has several, the route only sees the last one (see the "Three rows" example).

Studio, Talaxie et Talend RuntimeStudio, Talaxie and Talend Runtime

Rien ne change d'un environnement à l'autre : le composant n'a ni adresse ni option de sécurité, il écrit en mémoire dans le message de la route qui l'appelle. Seul le type Système a une portée différente : dans le Studio ou Talaxie, la machine Java est celle de l'exécution de la route ; dans le Runtime, c'est celle du conteneur, partagée par tout ce qui y est déployé. Nothing changes from one environment to another: the component has no address and no security option, it writes in memory into the message of the route that calls it. Only the System type has a different reach: in the Studio or Talaxie, the Java machine is that of the run of the route; in the Runtime, it is that of the container, shared by everything deployed there.

ExemplesExamples

Sorties copiées depuis l'exécution locale d'une route d'essai : cTimer → cSetBody → cSetHeader → cTalendJob → cProcessor. Le cProcessor, placé après l'appel du job, affiche ce que la route a reçu (lignes route:) ; les lignes job: viennent d'un tJavaRow du job. Le nom de la route est remplacé par MyRoute. Outputs copied from the local run of a test route: cTimer → cSetBody → cSetHeader → cTalendJob → cProcessor. The cProcessor, placed after the call of the job, prints what the route received (route: lines); the job: lines come from a tJavaRow of the job. The name of the route is replaced with MyRoute.

Les quatre types à la foisThe four types at once

row1 (Main) row2 (Main) tRouteInput_1 tJavaRow_1 tRouteOutput_1

La route envoie le corps A-1001 et les en-têtes customer = Alice et lines = 3. Le tRouteInput lit body, customer, lines (Integer) et route ("${routeId}"). Code du tJavaRow, puis table Camel du tRouteOutput : The route sends the body A-1001 and the headers customer = Alice and lines = 3. The tRouteInput reads body, customer, lines (Integer) and route ("${routeId}"). Code of the tJavaRow, then Camel table of the tRouteOutput:

System.out.println("job: body = " + input_row.body + ", customer = " + input_row.customer + ", lines = " + input_row.lines + ", route = " + input_row.route);
output_row.reply = "Order " + input_row.body + " accepted";
output_row.total = input_row.lines * 10;
output_row.audit = "checked";
output_row.last = input_row.body;
ColonneColumn Type NomName
reply (String)CorpsBody
total (Integer)En-têteHeader"total"
audit (String)PropriétéProperty"audit"
last (String)SystèmeSystem"demo.last.order"

Code du cProcessor de la route : Code of the cProcessor of the route:

System.out.println("route: body = " + exchange.getIn().getBody(String.class));
System.out.println("route: header total = " + exchange.getIn().getHeader("total") + " (" + exchange.getIn().getHeader("total").getClass().getSimpleName() + ")");
System.out.println("route: header customer = " + exchange.getIn().getHeader("customer"));
System.out.println("route: property audit = " + exchange.getProperty("audit"));
System.out.println("route: system demo.last.order = " + System.getProperty("demo.last.order"));
job: body = A-1001, customer = Alice, lines = 3, route = MyRoute_cTimer_1
route: body = Order A-1001 accepted
route: header total = 30 (Integer)
route: header customer = Alice
route: property audit = checked
route: system demo.last.order = A-1001

Le corps est remplacé, l'en-tête total arrive en Integer, et l'en-tête customer, posé par la route avant l'appel, est toujours là. The body is replaced, the total header arrives as an Integer, and the customer header, set by the route before the call, is still there.

Un corps XMLAn XML body

row1 (Main) row2 (Main) tRouteInput_1 tJavaRow_1 tRouteOutput_1

La route envoie <order><id>A-1001</id></order> ; le job, au schéma par défaut du tRouteInput (body, Document), ajoute un élément status et renvoie la colonne body (Document) en type Corps. Le cProcessor affiche la classe du corps reçu, puis le corps en texte. The route sends <order><id>A-1001</id></order>; the job, with the default schema of the tRouteInput (body, Document), adds a status element and sends the body column (Document) back with the Body type. The cProcessor prints the class of the received body, then the body as text.

job: id = A-1001
route: class = com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl
route: body = <order><id>A-1001</id><status>checked</status></order>

La route reçoit un document DOM, que ses composants XML (cSetBody en XPath, cMessageRouter…) lisent directement. The route receives a DOM document, which its XML components (cSetBody with XPath, cMessageRouter…) read directly.

Trois lignes, depuis un autre sous-jobThree rows, from another subjob

row1 (Main) OnSubjobOk row2 (Main) tRouteInput_1 tLogRow_1 tFixedFlowInput_1 tRouteOutput_1

Le tFixedFlowInput produit trois lignes, first, second, third, dans une colonne reply de type Corps. La route envoie deux messages de corps A-1001, que le tLogRow affiche. The tFixedFlowInput produces three rows, first, second, third, in a reply column with the Body type. The route sends two messages with body A-1001, which the tLogRow prints.

A-1001
route: body = third
A-1001
route: body = third

Chaque ligne a remplacé le corps ; la route n'a que la dernière. Le résultat est le même avec la case Invocation rapide de Job du cTalendJob. Each row replaced the body; the route only has the last one. The result is the same with the Fast Job Invocation box of the cTalendJob.

PiègesPitfalls

Un nom laissé videA name left empty

Le type par défaut d'une colonne est En-tête, et son Nom est vide. Laissée ainsi, la colonne reply empêche le job de compiler (nom du job remplacé par MyJob) : The default type of a column is Header, and its Name is empty. Left like this, the reply column prevents the job from compiling (job name replaced with MyJob):

MyJob.java:1395: error: illegal start of expression
	            	routerExchange_tRouteOutput_1.getIn().setHeader(, row2.reply);
	            	                                                ^
1 error

Donnez un nom à chaque colonne qui n'est pas le corps, entre guillemets : "status". Sans guillemets, le nom serait lu comme une variable Java. Give a name to each column that is not the body, in quotes: "status". Without quotes, the name would be read as a Java variable.

Un job sans tRouteInputA job without a tRouteInput

Un job fait d'un tFixedFlowInput relié à un tRouteOutput, sans tRouteInput. La génération du code échoue, avant toute compilation ; dans Talaxie : A job made of a tFixedFlowInput connected to a tRouteOutput, without a tRouteInput. The code generation fails, before any compilation; in Talaxie:

java.lang.IllegalStateException: Erreur dans le modèle esb/header_additional_talendesb_routerjob_datas
	…
Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	…

Le modèle de Talaxie qui prépare l'appel par la route cherche le tRouteInput du job dès qu'il y trouve un tRouteOutput ou un tRouteFault, sans vérifier qu'il existe. Un job qui renvoie des données à une route commence toujours par un tRouteInput, même s'il ne lit rien du message. The Talaxie template that prepares the call by the route looks for the tRouteInput of the job as soon as it finds a tRouteOutput or a tRouteFault there, without checking that it exists. A job that sends data back to a route always starts with a tRouteInput, even if it reads nothing from the message.

Le type Système dépasse le messageThe System type outlives the message

Une propriété système est globale à la machine Java : deux messages traités en même temps écrivent la même, et le dernier gagne. Ne vous en servez pas pour une donnée du message ; un en-tête ou une propriété de l'échange fait ce travail. Une valeur nulle y fait échouer le job (System.setProperty refuse null). A system property is global to the Java machine: two messages handled at the same time write the same one, and the last wins. Do not use it for a value of the message; a header or an exchange property does that job. A null value there makes the job fail (System.setProperty rejects null).

Un seul corpsA single body

Rien n'empêche de donner le type Corps à deux colonnes : elles sont écrites l'une après l'autre, dans l'ordre de la table, et seule la dernière reste. Un corps de type Document doit être renseigné : le composant en demande le texte XML sans tester s'il est nul. Nothing prevents giving the Body type to two columns: they are written one after the other, in the order of the table, and only the last one remains. A body of type Document must be set: the component asks for its XML text without testing whether it is null.

Pas de déclencheurNo trigger

Aucun lien On Component Ok ou Run if ne part du tRouteOutput. Pour enchaîner après la réponse, partez du premier composant du sous-job avec On Subjob Ok : la suite s'exécute avant le retour à la route, qui attend la fin du job. No On Component Ok or Run if link leaves the tRouteOutput. To chain after the reply, start from the first component of the subjob with On Subjob Ok: what follows runs before the return to the route, which waits for the end of the job.

Répondre n'est pas signaler une erreurReplying is not reporting an error

Après un tRouteOutput, la route suit son chemin normal, même si l'en-tête renvoyé dit REFUSED : c'est à elle de le tester. Pour que la route parte dans son traitement d'erreur (cOnException, cTry), utilisez un tRouteFault. After a tRouteOutput, the route follows its normal path, even if the returned header says REFUSED: testing it is up to the route. For the route to go into its error handling (cOnException, cTry), use a tRouteFault.

ConseilsTips

Un en-tête pour aiguiller la routeA header to steer the route

Renvoyez, à côté du corps, un en-tête court ("status") que la route teste dans un cMessageRouter : ${header.status} == 'ACCEPTED'. Le job décide, la route aiguille, et le corps n'a pas à être relu. Send back, next to the body, a short header ("status") that the route tests in a cMessageRouter: ${header.status} == 'ACCEPTED'. The job decides, the route steers, and the body does not have to be read again.

Ramener le flux à une ligneBring the flow down to one row

Si le job produit plusieurs lignes, regroupez-les avant le tRouteOutput : un tAggregateRow pour un total, un tXMLMap ou un tWriteJSONField pour un document unique. La route reçoit alors un corps complet au lieu de la dernière ligne. If the job produces several rows, group them before the tRouteOutput: a tAggregateRow for a total, a tXMLMap or a tWriteJSONField for a single document. The route then receives a complete body instead of the last row.

Voir aussiSee also