WELCOME Abdennour : Software engineer

Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts

Nov 15, 2012

introduction to Integration and Spring Integration

Integration?
Integration
 means connecting computer systems, companies, and people .

Older solutions used platform agnostic RPC like CORBA and Oracle (formerly BEA’s) Tuxedo to integrate. 

What pb solved by Integration?
   -horizontal problem of integrating data and services between disparate(heterogeneous) applications across the enterprise. 
Frameworks of Integration:
 integration frameworks like Apache Camel and Spring Integration 

Integration Target :
  Enterprise Application Integration (EAI)

Integration product : 

webMethods,Tibco, BusinessWare ( Vitria ) ,M3O(Vitria),IBM MQSeries , SonicMQ ,Axway Integrator ,Oracle SOA Suite(he message broker and application server from WebLogic and the message router from BEA AquaLogic.),Microsoft BizTalk

Challenge of integration :
The challenge of integration is to enable applications to share functionality and data in real time without
tightly coupling the systems together in a way that introduces reliability issues in terms of application
execution and application development.

EAI Goal :
 EAI seeks to simplify and automate business processes without requiring comprehensive changes to the existing applications and data structures.



Integration Approaches : 


     1.file transfer, :good but has performances issues
     2.sharing a database,: it's single for many
     3.leveraging services : are slower and have the potential to fail.
    4.  asynchronous messaging: Messaging is an approach to transfer packets of data frequently, immediately, reliably, and asynchronously using a customizable format.

Benefits of Messaging : 

    1.Messages can be transformed in transit without either the sender or receiver knowing about the modification. 
    2.Both data and processes may be shared using messaging. 
    3. Message may be broadcasted to multiple receivers or directed at one of many receivers.             
    4.Messaging meets the needs for integration scalability and extensibility.
    5.Messaging decouples the producer and the consumer—they don’t need to know about when the other is available, nor do the producer and the consumer need to be aware of the other’s public interface or its speed.


Two approaches to communicating data across systems(obtaining data):

1)a pull system :the client needs to ask for the information . (traditional approach)
     Tools:a database query, a remote procedure call, or a web service ...

2) a push system :the remote system needs to send the data when something has changed .
==>Integrations are often point-to-point(where any interested party needs to know how to speak to any other system directly to obtain a result. )


Q:how much different connections are required for any number of partners in a system that need to communicate with each other using point-to-point communication?

A:n(n − 1)/2 – where n is the number of connected nodes–can yield some very scary results

=>We need EDA for messaging (consumption of events as messages).

What's EDA?
- Where information is published as events (in messages) as soon as data is available.

-EDA is an architecture where events are transmitted between loosely coupled software components and services.

Event Driven Architecture:

-Event Driven Architecture (EDA) is a software architecture pattern promoting the production,
detection, and/or consumption of events as messages

Advantges : 
   
an event-based architecture allows these applications and systems to be more responsive


-SEDA(staged EDA) =thread and event+based approach. 
   -build a system that can support massive concurrency without incurring many of the issues involved
   -Hypothese : The basic premise is to break the application logic into a series of stages connected by
event queues.

Types of coupling approches to integration & architecture Application : 

Three types of coupling approches to integration & architecture Application : 
    1.Spatial coupling (communication): 

    2.Temporal coupling(buffering): 

    3.Logical coupling (routing):

EAI Architecture:

-EAI moved to message brokers.
-The connection to the disparate applications was done using an adapter to convert the application protocol to something the message broker would understand. 

-the adapter software was usually run inside of some sort of container.
=> provide basic application support as configuration and lifecycle ....

-Eventually, the application servers and adapter containers merged together 


Enterprise service bus (ESB):
- a lightweight adapter container with message routing capabilities based on open standards


    EBS provides : 
           -Server features
                  + 
            -ready-to-go routing and integration technologies.


*Integration Server:
 -provides a platform to integration between companies over the Internet.
 - Essentially an HTTP server on steroids, the Integration Server was developed to support B2B integration.
 - support for EDI and custom XML messages, and its own process flow language.


EAI Patterns :

Three basic patterns  when implementing integrations for enterprise customers



  1-data synchronization, 

 -used when business processes in different parts of an organization require access to the same data.
-each application has its own technology stack

Integration Approch : using a message-based system to move the data records inside the messages.
 -How detect the Creation or the Update of record ? =>By DB Trigger ,Hook or Façade


  2-Web portals


-Web portals aggregate information from several different data sources into a single display without requiring the user to log in into the different applications supporting the various business areas.
-Used to get a general overview of the entire organization. 


  3-workflow system. 

-Used when  A business process can span multiple business areas and systems within an organization, and may require both automatic agents and human actors to complete successfully.

-workflow engines(which represent a process flow) : BPEL, BPMN....

-integrating the workflow process with the different applications using an integration framework .







Popular open source integration frameworks:
1.Mule ESB
2.Apache Service Mix

Four  integration approaches:
• Mule provides a lightweight container and leverages a simple XML configuration file and Plain Old Java Objects (POJOs).
• ServiceMix is based on the Java Business Integration (JBI) standard and now  supports OSGI.
• OpenESB is  the integration offering from Oracle based on the JBI and J2EE standards. OpenESB live in a J2EE application server like GlassFish.
•  the do-it-yourself (DIY) approach. J2EE does provide the  necessary support to implement integration, including the J2EE Connector Architecture (JCA). JCA is the J2EE framework for creating resource adapters (RAs) for connecting with external applications and systems.

Note : 
Camel, Mule, and ServiceMix all support the Spring Framework as a component model .



2.ServiceMiX :

>ServiceMix is a standalone JBI container
>engine Camel support.
(Camel :allows simple configuration of routing and mediation rules. )
>All components deployed to ServiceMix must follow either

the JBI(Messaging in XML Format) or OSGi standard. 
>ActiveMQ is included for remoting, clustering,reliability, and distributed failover.



References :

Spring Integration

Nov 11, 2012

Spring bean thread scope



 How beans are defined in the IoC container ?
Spring uses the notion of bean scopes to answer to this question .


we have 6 scopes : 
  >singleton, prototype, thread ,request, session, and globalSession . 

the new Scope in the Spring 3.0 is thread . 
Note: Singleton, prototype ,request, session, and globalSession Scopes are explained in this tutorial.

Thread Scope  Utility : 
>it Creates a bean instance per thread. Similar to request scope.

Thread Scope VS Request Scope:
>Thread Scope is available to all context implemenetation scope .
>Request Scope is available only to application contexts (web-freindly)


Note : Thread Scope requires registration with the CustomScopeConfigurer bean.


Illustration of Thread Scope Behavior :





1.Create Maven Project : 


2.Edit pom.xml file & add Spring 3 Dependencies : 


 <properties>
    <spring.version>3.0.5.RELEASE</spring.version>
  </properties>
  <dependencies>
    <!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
  </dependencies>

_______________________________

3.Create Class for Spring instanciation Test : 
>slm.abdennour.springcore.Cv

package slm.abdennour.springcore;
import java.util.Random;
/**
*
* @author Abdennour عبد النور التومي
*
* @see http://abdennour-insat.blogspot.com
* @since 10 nov. 2012
*/
public class Cv {
    private String fullName;
    public Cv() {
     this.fullName=getRandomString();
}
    public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public void display(){
     System.out.println(this.fullName);
    }
public String getRandomString(){
char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < 20; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
String output = sb.toString();
return output;
}
}


4.Create Runnable Class & Main Method:


package slm.abdennour.springcore;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
* @author Abdennour عبد النور التومي
*
* @see http://abdennour-insat.blogspot.com
* @since 11 nov. 2012
*/
public class CvRun implements Runnable {
ApplicationContext ctx;
public CvRun(ApplicationContext ctx) {
// TODO Auto-generated constructor stub
this.ctx = ctx;
}
public final void run() {
// TODO Auto-generated method stub
try {
Cv cvChild = ctx.getBean("cvThread", Cv.class);
System.out.println("Cv Thread Child =>" + cvChild.getFullName());
} finally {
// TODO: handle exception
}
}
public static void main(String[] args) {
ApplicationContext appCtx=new ClassPathXmlApplicationContext("ctx.xml");
Cv cvPatent = appCtx.getBean("cvThread", Cv.class);
System.out.println("Cv Thread Parent =>" + cvPatent.getFullName());
//Cv THread
CvRun cvrun=new CvRun(appCtx);
new Thread(cvrun).start();
//Cv Simple
System.out.println("Simple");
for (int j = 0; j < 5; j++) {
System.out.print("cv Simple "+j+"=>");
((Cv)appCtx.getBean("cvSimple", Cv.class)).display();
}
}
}

5.Add two beans in Spring Config XML : 
> one for singleton scope (which is the default scope)
>other for thread scope .


    <bean
        id="cvSimple"
        class="slm.abdennour.springcore.Cv"
         >
        
    </bean>
    <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer" >
        <property name="scopes" >
            <map>
                <entry key="thread" >
                    <bean class="org.springframework.context.support.SimpleThreadScope" />
                </entry>
            </map>
        </property>
    </bean>
    <bean
        id="cvThread"
        class="slm.abdennour.springcore.Cv"
         scope="thread">
        
    </bean>


 
6.Run & Result :
 As the default scope is Singleton, cvSimple beans are the Same for all instanciation of Spring Factory container.  

7.Source Code : 





                              

Nov 2, 2012

Creating Spring Roo project from existing DataBase(Reverse Engineering)


                                     


Method 1 :

1. Open roo shell
 $roo

2.Create your project and set the main configuration then Enter this Command :
roo>persistence setup --provider HIBERNATE --database MYSQL --databaseName consultationmedicale --userName root --password 0000

NOTE: Don't forget to replace "root" by  your MySql UserName and "0000" by your MySql password




3.addon install bundle :
roo> bundle --bundleSymbolicName org.springframework.roo.wrapping.mysql-connector-java

4.Add MySql Connector Jar too Context :
roo> osgi start --url file:///C:/path/to/mysql-connector-java-5.1.18-bin.jar

5.Generate XML Description of Database 
roo> database introspect --schema consultationmedical
Note : Replace "consultationmedical" by your database Name .


Result
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.--><database name="deprecated">
    <option key="moduleName" value=""/>
    <option key="activeRecord" value="false"/>
    <option key="includeNonPortableAttributes" value="true"/>
    <option key="testAutomatically" value="false"/>
    <table name="consultation">
        <column name="idc" primaryKey="true" required="true" scale="0" size="10" type="4,INT"/>
        <column name="datec" primaryKey="false" required="false" scale="0" size="45" type="12,VARCHAR"/>
      .
      ..
   .. ... 

    </table>
</database>

Sep 15, 2012

[NEWS] Spring Integration In Action




SPRING INTEGRATION IN ACTION PUBLISHED AND AVAILABLE TODAY




Spring Integration extends the Spring Framework to support the patterns described in Gregor Hohpe and Bobby Woolf's Enterprise Integration Patterns. Like the Spring Framework itself, it focuses on developer productivity, making it easier to build, test, and maintain enterprise integration solutions.

Sep 10, 2012

[NEWS] Spring Social Facebook 1.0.2 Released

The Spring team publishes today version 1.0.2 of Spring Social Facebook.
The team announcement is below

According to the official site of Spring(CLick Here):

SPRING SOCIAL FACEBOOK 1.0.2 RELEASED

Dear Spring Community,
We are pleased to announce the release of Spring Social Facebook 1.0.2!
This release primarily adjusts Spring Social Facebook's API binding to some recent and upcoming changes in the Facebook Graph API. Specifically:
  • The "picture" field of many objects in the Facebook's Graph API is changing from a simple string containing the URL to an object with additional information about the picture. Spring Social Facebook's API binding has been changed to handle either form and return the URL string.
  • The "likes" field of the Graph API's Comment object has been renamed to "like_count". Spring Social Facebook's API binding has been changed to bind to the new "like_count" field.
  • The picture property of Page, Post, and Video has been deprecated. While it will still return the URL string for a picture in 1.0.2, this property will be replaced in Spring Social Facebook 1.1.0 with one that returns an object with more complete metadata about the picture.
  • The position property of the Photo object has been deprecated, as this property will no longer be populated by the Facebook Graph API. This property will be removed in Spring Social Facebook 1.1.0.
To get the software, download the release distribution or simply add/update the maven artifacts to your project:
<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-facebook</artifactId>
    <version>1.0.2.RELEASE</version>
</dependency>
We are continuing to monitor any changes that Facebook may apply in their graph API and if an adjustment in Spring Social Facebook's API binding is required, will release followup maintenance releases with those adjustments. We are also looking ahead to the 1.1.0 release of Spring Social, Spring Social Twitter, and Spring Social Facebook with some exciting new features in the coming months. We invite you to participate in the discussion in theSpring Social forum, in the issue tracker (Core|Facebook|Twitter), or at GitHub (Core|Facebook|Twitter).
REFERENCE :