Gateway
Gateways are message endpoints which provide two-way integration. It can be used as bidirectional or request-reply adapter unlike channel adapter which is unidirectional. Similar to adapters gateways are of two types namely:
- Inbound Gateway – It brings message into the application and then waits for the response.
- Outbound Gateway – It invokes external applications/systems and feeds the response back into the application.
In EAI, gateway can be pictorially represented as shown in Figure 22-15 below.
Figure 22-15. Message Gateway
Application to application interaction using gateway endpoint can be pictorially represented as shown in Figure 22-16 below.
Figure 22-16. Application to application interaction using gateway endpoint
In our sample application, for dealing with booking we have another service interface as shown in Listing 22-7 below.
Listing 22-7. BookingService Interface
1 2 3 4 5 6 7 8 9 10 11 |
package com.mybook.loyalty.service; public interface BookingService { //… public BookingConfirmation createBooking(Booking booking); //… } |
The gateway is defined in Spring configuration file namely applicationContext.xml as shown in Listing 22-8 below.
Listing 22-8. Gateway declaration in Spring configuration file
1 |
<gateway id=”bookingService” service-interface=”com.mybook.loyalty.service.BookingService” default-request-channel=”bookingChannel”/> |
Declaring gateway serves as a proxy for sending new messages and even after doing so your application code doesn’t depend on the core Spring Integation API’s which is really advantageous to avoid third party integration issues. By default temporary reply channel is created automatically for Listing 22-8 but if you want you can also specify default-response-channel as well.
The gateway method signature can have “void” as well as “Future” return types. In the case of “void” return type, it effectively turns into a passive inbound adapter and in case of “Future” return type, it becomes effectively as a asynchronous and non-blocking gateway.
Declaring gateway using Java annotation turns the service interface as shown in Listing 22-9 below.
Listing 22-9. BookingService interface using Java annotations to declare gateways
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
package com.mybook.loyalty.service; public interface BookingService { //… @Gateway(requestChannel=”bookingChannel”) public Future<BookingConfirmation> createBooking(Booking booking); @Gateway(requestChannel=”bookingCancellationChannel”) public void cancelBooking(Booking booking); //… } |
Listing 22-10 shows declaration of Inbound Web Service gateway and Figure 22-17 shows the same pictorially.
Listing 22-10. Declaring inbound web service gateway in Spring configuration file
1 2 3 |
<int-ws:inbound-gateway id=”wsSampleGateway” channel=”fromWSSample” marshaller=”jaxb2Sample” unmarshaller=” jaxb2Sample”/> <oxm:jaxb2-marshaller id=” jaxb2Sample” contextPath=”com.mybook.sample.xml”/> |
Figure 22-17. Inbound Web Service gateway
Page Visitors: 13000


Tomcy John


Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
Hi,
Thanks for this blog and information sharing!
I have one question from Spring Integration. Just thought of checking with you.
I have SimplewebserviceOutBoundGateway. I need to send a document / attachment to the webservice. How will i achieve that?
This is my current gateway configuration:
Please let me know, if you can throw some light in this area.
Thanks in Advance!
Hi,
Thank you for your information sharing.
I have one doubt,could you please suggest me the correct frameworks to address that issue.
My requirement is I would like to get and process files using spring and camel.
Thanks,
Madhu