issue76:tutoriel_-_spring_integration
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue76:tutoriel_-_spring_integration [2014/02/10 22:16] – [3] fredphil91 | issue76:tutoriel_-_spring_integration [2014/02/11 14:50] (Version actuelle) – [8] auntiee | ||
---|---|---|---|
Ligne 4: | Ligne 4: | ||
Before delving deeper, let me explain what Spring Integration is intended for. As their site suggests: “it provides an extension of the Spring programming model to support the well-known Enterprise Integration Patterns”. Rephrasing, to design good enterprise applications one could use messaging (more precisely asynchronous messaging) that enables diverse applications to be integrated with each other – without nightmares or pain. A wise guy named Martin Fowler has written a famous book: “Enterprise Integration Patterns”. Folks from Spring probably one day decided to materialize a theory into practice. Very pragmatic approach, isn’t it? Later, you will see how wonderful it is for regular tasks. The main concept of SI is: Endpoint, Channel and Message.** | Before delving deeper, let me explain what Spring Integration is intended for. As their site suggests: “it provides an extension of the Spring programming model to support the well-known Enterprise Integration Patterns”. Rephrasing, to design good enterprise applications one could use messaging (more precisely asynchronous messaging) that enables diverse applications to be integrated with each other – without nightmares or pain. A wise guy named Martin Fowler has written a famous book: “Enterprise Integration Patterns”. Folks from Spring probably one day decided to materialize a theory into practice. Very pragmatic approach, isn’t it? Later, you will see how wonderful it is for regular tasks. The main concept of SI is: Endpoint, Channel and Message.** | ||
- | Il y a quelque temps, j'ai commencé un nouveau boulot dans une grande société. Ma première tâche était de réimplémenter/ | + | Il y a quelque temps, j'ai commencé un nouveau boulot dans une grande société. Ma première tâche était de réimplémenter/ |
- | Avant de plonger plus profondément, | + | Avant d' |
====== 2 ====== | ====== 2 ====== | ||
Ligne 15: | Ligne 15: | ||
An important thing with SI is a configuration file which contains all the necessary components we’re going to use. Here is the “server” part of the configuration. Simplifying a model and SI lifecycle, Spring creates objects that are defined in the configuration xml. More generally, such a concept is called declarative programming. You define a business object in the xml, and a framework generates appropriate classes for you, and injects and initializes dependencies. The mantra says: you should be concentrated only on the business and not on the implementation.** | An important thing with SI is a configuration file which contains all the necessary components we’re going to use. Here is the “server” part of the configuration. Simplifying a model and SI lifecycle, Spring creates objects that are defined in the configuration xml. More generally, such a concept is called declarative programming. You define a business object in the xml, and a framework generates appropriate classes for you, and injects and initializes dependencies. The mantra says: you should be concentrated only on the business and not on the implementation.** | ||
- | Le nœud d' | + | Le nœud d' |
La prochaine étape pour notre cours intensif sera de définir les exigences. Je dirais que nous avons besoin d'un serveur (tcp) et d'un client tcp. Nous allons écrire une application simple qui va échanger quelques messages entre les deux. | La prochaine étape pour notre cours intensif sera de définir les exigences. Je dirais que nous avons besoin d'un serveur (tcp) et d'un client tcp. Nous allons écrire une application simple qui va échanger quelques messages entre les deux. | ||
- | Une chose importante dans le SI est un fichier de configuration qui contient tous les composants que nous allons utiliser. Voici la partie « serveur » de la configuration. Pour simplifier le modèle et le cycle de vie du SI, Spring crée des objets qui sont définis dans le fichier xml de configuration. Plus généralement, | + | Une chose importante dans le SI est un fichier de configuration qui contient tous les composants que nous allons utiliser. Voici la partie « serveur » de la configuration. Pour simplifier le modèle et le cycle de vie du SI, Spring crée des objets qui sont définis dans le fichier xml de configuration. Plus généralement, |
====== 3 ====== | ====== 3 ====== | ||
Ligne 30: | Ligne 30: | ||
Nous allons définir une partie du fichier xml de configuration (page suivante, en haut à gauche), la partie serveur : http:// | Nous allons définir une partie du fichier xml de configuration (page suivante, en haut à gauche), la partie serveur : http:// | ||
- | Les choses importantes sont : une usine (tcp-connection-factory) | + | Les choses importantes sont : une usine (tcp-connection-factory) crée un serveur TCP en utilisant un tableau sérialiseur d'une longueur d'un octet. Un sérialiseur est nécessaire pour « emballer » notre message, c-à-d l' |
- | Nous avons également défini deux canaux : serverIn (pour les messages entrants) et serverOut (pour les messages sortants). Pour que notre serveur puisse envoyer et recevoir des messages, nous définissons des adaptateurs entrants et sortants qui sont associés à l' | + | Nous avons également défini deux canaux : serverIn (pour les messages entrants) et serverOut (pour les messages sortants). Pour que notre serveur puisse envoyer et recevoir des messages, nous définissons des adaptateurs entrants et sortants qui sont associés à l' |
====== 4 ====== | ====== 4 ====== | ||
- | I would say a couple of words about the SI lifecycle. Spring framework has two “main” packages: | + | **I would say a couple of words about the SI lifecycle. Spring framework has two “main” packages: |
that build up the core utility of the dependency injection of the component. The org.springframework.beans.factory.BeanFactory interface provides basic lifecycle methods (start and stop) for bean initialization/ | that build up the core utility of the dependency injection of the component. The org.springframework.beans.factory.BeanFactory interface provides basic lifecycle methods (start and stop) for bean initialization/ | ||
Our server is ready... I mean, completely ready. To run the example, follow the below steps: | Our server is ready... I mean, completely ready. To run the example, follow the below steps: | ||
+ | |||
+ | cd /tcpserver | ||
+ | |||
+ | mvn clean install | ||
+ | |||
+ | mvn dependency: | ||
+ | |||
+ | mvn exec:java -Dexec.mainClass=" | ||
+ | |||
+ | Je voudrais dire quelques mots sur le cycle de vie du SI. Le framework Spring a deux paquets « principaux » : org.springframework.beans et org.springframework.context | ||
+ | qui construisent l' | ||
+ | |||
+ | Notre serveur est prêt... Je veux dire, tout à fait prêt. Pour exécuter l' | ||
cd /tcpserver | cd /tcpserver | ||
Ligne 49: | Ligne 62: | ||
====== 5 ====== | ====== 5 ====== | ||
- | Our main class expresses as shown in the box below. | + | **Our main class expresses as shown in the box below. |
The source code can be found here http:// | The source code can be found here http:// | ||
Ligne 59: | Ligne 72: | ||
Finally, for the server, write an error handler which logs the errors which is shown above. Code is at: http:// | Finally, for the server, write an error handler which logs the errors which is shown above. Code is at: http:// | ||
- | At this point, we’re done with our server. | + | At this point, we’re done with our server.** |
+ | |||
+ | Notre classe principale s' | ||
+ | |||
+ | Le code source peut être trouvé ici : http:// | ||
+ | |||
+ | Nous définissons également un service d' | ||
+ | |||
+ | Ensuite, voici un exécuteur du boulot. Ce code-là est montré sur la page suivante, en bas à gauche. Le code peut être récupéré ici : http:// | ||
+ | |||
+ | Enfin, pour le serveur, nous écrivons un gestionnaire d' | ||
+ | |||
+ | À ce stade, nous en avons terminé avec notre serveur. | ||
====== 6 ====== | ====== 6 ====== | ||
- | Now, let’s define a tcp client which connects to the server, sends an accept message, and gets a file sent from the server. | + | **Now, let’s define a tcp client which connects to the server, sends an accept message, and gets a file sent from the server. |
Our configuration file looks as follows: http:// | Our configuration file looks as follows: http:// | ||
Ligne 77: | Ligne 102: | ||
mvn exec:java -Dexec.mainClass=" | mvn exec:java -Dexec.mainClass=" | ||
- | Almost the same logic applies here. Have a look. A main class has the lines shown in the code on the next page, top left. | + | Almost the same logic applies here. Have a look. A main class has the lines shown in the code on the next page, top left.** |
+ | |||
+ | Maintenant, nous allons définir un client TCP qui se connecte au serveur, envoie un message d' | ||
+ | |||
+ | Notre fichier de configuration se présente comme suit : http:// | ||
+ | |||
+ | Voici comment faire fonctionner un client : | ||
+ | |||
+ | Ouvrez un nouveau terminal : | ||
+ | |||
+ | cd / | ||
+ | |||
+ | mvn clean install | ||
+ | |||
+ | mvn dependency: | ||
+ | |||
+ | mvn exec:java -Dexec.mainClass=" | ||
+ | |||
+ | C'est presque la même logique qui s' | ||
====== 7 ====== | ====== 7 ====== | ||
- | In addition, define a client service: | + | **In addition, define a client service: |
void send(String txt); | void send(String txt); | ||
Ligne 98: | Ligne 141: | ||
That’s it! | That’s it! | ||
- | To play with the code, see here: http:// | + | To play with the code, see here: http:// |
+ | En outre, on définit un service client : | ||
+ | |||
+ | void send(String txt); | ||
+ | |||
+ | Ensuite, un gestionnaire de messages : | ||
+ | |||
+ | public void handle(byte[] s) { | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | } | ||
+ | |||
+ | Et le dernier est un intercepteur, | ||
+ | |||
+ | C'est tout ! | ||
+ | |||
+ | Pour vous amuser avec le code, voir ici : http:// | ||
====== 8 ====== | ====== 8 ====== | ||
- | Prerequisites: | + | **Prerequisites: |
• Java 1.6 or above; | • Java 1.6 or above; | ||
• Maven 3 or above; | • Maven 3 or above; | ||
Ligne 117: | Ligne 179: | ||
Cons: | Cons: | ||
• Takes time to learn and understand how to work with it. | • Takes time to learn and understand how to work with it. | ||
- | • If you get problems, sometime it is difficult to debug it. | + | • If you get problems, sometime it is difficult to debug it.** |
+ | |||
+ | Pré-requis : | ||
+ | • Java 1.6 ou supérieur ; | ||
+ | • Maven 3 ou supérieur ; | ||
+ | • le désir d' | ||
+ | |||
+ | Avantages : | ||
+ | • un grand nombre de fonctionnalités ; | ||
+ | • testé ; | ||
+ | • communauté amicale et agréable ; | ||
+ | • si vous avez des questions, les gens répondent très rapidement ; | ||
+ | • il y a des tonnes d' | ||
+ | • API simple et complète. | ||
+ | |||
+ | Inconvénients : | ||
+ | • il faut du temps pour apprendre et comprendre comment l' | ||
+ | • si vous avez des problèmes, il est parfois difficile de déboguer. | ||
issue76/tutoriel_-_spring_integration.1392066979.txt.gz · Dernière modification : 2014/02/10 22:16 de fredphil91