Transcript
Page 1: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

1 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

Messaging Systems

This chapter introduces the fundamental building blocks of a messaging system, such as

endpoints, messaging channels, and message routers.

، کلالل یلا نیلا (endpoints) شاال ب وک ه یلا ایااک یس ماایااارس نیلا رماالا لایا ا ل نلیلا درساین

و روتر یلا نیلا رملا امت.رملا

1- Message

A message is the smallest unit for transmitting data in a messaging system (represented by the grey dot in the figure below). The message itself might have some internal structure—for example, a message containing multiple parts—which is represented by geometrical figures attached to the grey dot in Figure 7.

Figure 7. Message Pattern

یس نیلا ک چکررین واحا وراا اار لل داده یل در مااایاااارس نیلا امااات. یس نیلا ود م دا م د کن امااات

مالمرلر دامک اا داشارد ولشا. ود وی اا للل یس نیلا شل ب چیاین و ا امت کد ت ما اشکلل ییام در

رصب ود ا طد ملکاررا راگ اشلا داده شاه امت. 7شکب

2- Message Channel

A message channel is a logical channel in a messaging system. That is, sending messages to different message channels provides an elementary way of sorting messages into different message types. Message queues and message topics are examples of message channels. You should remember that a logical channel is not the same as a physical channel. There can be several different ways of physically realizing a logical channel.

In Apache Camel, a message channel is represented by an endpoint URI of a message-oriented component as shown in Figure 8.

Page 2: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

2 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

Figure 8. Message Channel Pattern

کلالل فیزیک تفلوت دارد و یکااالا لکلالل نیلا : یس کلالل یط در یس ماایااارس نیلا اماات. کلالل یط و

ایات.

3- Message Endpoint

A message endpoint is the interface between an application and a messaging system. As shown in Figure 9, you can have a sender endpoint, sometimes called a proxy or a service consumer, which is responsible for sending In messages, and a receiver endpoint, sometimes called an endpoint or a service, which is responsible for receiving In messages.

Figure 9. Message Endpoint Pattern

اماات کد ت ااا یس نروکااا یل صااره کییاه رماالا نیلا ماایااارس و افزار ارا وین راوا نیلا نلیلا ا طد

ما لت ولشا. گلی اوقلت ا طد نلیلا یس مرویس ال یاه ش د کد ائ ل دریلفت نیلا امت.

4- Pipes and Filters

The pipes and filters pattern, shown in Figure 10, describes a way of constructing a route by creating a chain of filters, where the output of one filter is fed into the input of the next filter in

Page 3: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

3 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

the pipeline (analogous to the UNIX pipe command). The advantage of the pipeline approach is that it enables you to compose services (some of which can be external to the Apache Camel application) to create more complex forms of message processing.

Figure 10. Pipes and Filters Pattern

ل لد یل و فیکرریلا الگ ، وراا ت یای رو مالمت یس اایر یل ای لد یا یره اا ای فیکرریل امرفلده ش د

س فیکرر ود ورودا فیکرر وعاا رصب امت. کد در آا مروج ی

5- Message Router

A message router, shown in Figure 13, is a type of filter that consumes messages from a single consumer endpoint and redirects them to the appropriate target endpoint, based on a particular decision criterion. A message router is concerned only with redirecting messages; it does not modify the message content.

Figure 13. Message Router Pattern

روتر نیلا، یس ا ع فیکرر امت کد نیلا ای ا طد نلیلا صره کییاه ود ا طد یاه یلمب ور املس عیلر ملص

تص یس گیرا، تغییر کیا. روتر نیلا ور املس حر ا تغییر ا کیا.

6- Message Translator

The message translator pattern, shown in Figure 14 describes a component that modifies the contents of a message, translating it to a different format. You can use Apache Camel's bean integration feature to perform the message translation.

Page 4: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

4 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

Figure 14. Message Translator Pattern

الگ ا ترج د نیلا، تغییر حر اا یس نیلا را ت یی کیا و نیلا را ود فر ت یلا رک ترج د کیا.

Messaging Channels

Messaging channels provide the plumbing for a messaging application. This chapter describes the different kinds of messaging channels available in a messaging system, and the roles that they play.

رملا را فرایس کییا. نیلا ورال د یس وراا کش ل لد رملا نیلا یلا کلالل

1- Point-to-Point Channel

A point-to-point channel, shown in Figure 15 is a message channel that guarantees that only one receiver consumes any given message. This is in contrast with a publish-subscribe channel, which allows multiple receivers to consume the same message. In particular, with a point-to-point channel, it is possible for multiple receivers to subscribe to the same channel. If more than one receiver competes to consume a message, it is up to the message channel to ensure that only one receiver actually consumes the message.

Figure 15. Point to Point Channel Pattern

، شررهکلالل اارشلر کلالل ا طد ود ا طد، تضا ین کیا کد گیرااه یر نیلا تیال یک امت. کد این و ع ول

در تضاالد امااات کد اجلیه دیا گیرااه یلا رعاد آا نیلا را وگیراا.اگر ویا ای یس گیرااه وج د داشااارد

ولشا، ولیا اط ییلا نیاا کرد کد گیرااه االی ف ا یک ولشا.

Page 5: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

5 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

2- Publish-Subscribe Channel

A publish-subscribe channel, shown in Figure 16, is a message channel that enables multiple subscribers to consume any given message. This is in contrast with a point-to-point channel. Publish-subscribe channels are frequently used as a means of broadcasting events or notifications to multiple subscribers.

Figure 16. Publish Subscribe Channel Pattern

کلالل اارشاالر شاارره، یس کلالل اار لل اماات وراا دریلفت نیلا ت مااا چیاین شاارره. کد این کلالل ول کلالل

کلا شرر وراا اطالوید یل در مایاارس یلا رادی و تک یزی ا ای این کلالل ع الًا طد ود ا طد در تضالد امات.

.ش د امرفلده رک

3- Dead Letter Channel

The dead letter channel pattern, shown in Figure 17, describes the actions to take when the messaging system fails to deliver a message to the intended recipient. This includes such features as retrying delivery and, if delivery ultimately fails, sending the message to a dead letter channel, which archives the undelivered messages.

Figure 17. Dead Letter Channel Pattern

Page 6: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

6 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

کلالل نیلا رده )ای وین رفرد( اقاا لت کد ماایااارس نیلا ار ااا آا نیلا را ود گیرااه ارماالل کیا، را ت یاای

اجد شا، شاکات ول االیت در تح یب اگر و ،وراا تح یب اد ماع قبیب ای یلا ویژگ شال ب کیا. این

اشاه ولشا. تح یب نیلا آرشی و رده، کلالل ود نیلا ارملل

4- Guaranteed Delivery

Guaranteed delivery means that once a message is placed into a message channel, the messaging system guarantees that the message will reach its destination, even if parts of the application should fail. In general, messaging systems implement the guaranteed delivery pattern, shown in Figure 18, by writing messages to persistent storage before attempting to deliver them to their destination.

Figure 18. Guaranteed Delivery Pattern

صا دو نیلا این کد کیا تض ین نیلا تض ین تح یب ود عیلا قرار دادا یس نیلا در کلالل امت. میارس

ول شااکااات اجد شاا د. )نیلا ود یاا رت ااوا تل رماایاا ود افزار ارا ای یلی و ا اگر حر ورمااا، م د

صا ذمیره ش د(

Page 7: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

7 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

5- Message Bus

Message bus refers to a messaging architecture, shown in Figure 19, that enables you to connect diverse applications running on diverse computing platforms. In effect, the Apache Camel and its components constitute a message bus.

Figure 19. Message Bus Pattern

ر و ااایب ولس، شااا ل را قلدر ماالید ود ورقرارا ارتبل و اتصااالل ود ورال د یلا کلروردا ری ع در حلل اجرا

فرا یلا حلمبلت گ الگ ا.روا نکر

Page 8: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

8 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

Message Routing

The message routing patterns describe various ways of linking message channels together. This includes various algorithms that can be applied to the message stream (without modifying the body of the message).

شای ه یلا رک نیلا را ای کلالل یل ول یس ت یی کیا. شل ب الگ ریرس یلا روتر نیلا ) اایریلو نیلا( :

( رک امت وراا او لل جریلا نیلا )واوا تغییر وااد نیلا

1- Content-Based Router

A content-based router, shown in Figure 21, enables you to route messages to the appropriate destination based on the message contents.

روتر بری ور نیلا : ش ل را قلدر ملید تل نیلا یل را ور املس حر ا ود صا یلمب وفرمریا.

Figure 21. Content-Based Router Pattern

2- Message Filter

A message filter is a processor that eliminates undesired messages based on specific criteria. In Apache Camel, the message filter pattern, shown in Figure 22, is implemented by the filter() Java DSL command. The filter() command takes a single predicate argument, which controls the filter. When the predicate is true, the incoming message is allowed to proceed, and when the predicate is false, the incoming message is blocked.

Figure 22. Message Filter Pattern

لا الم امرد ور املس عیلریلا ملص.فیکرر نیلا : یس نردایااه وراا حذه نیلا ی

Page 9: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

9 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

3- Recipient List

A recipient list, shown in Figure 23, is a type of router that sends each incoming message to multiple different destinations. In addition, a recipient list typically requires that the list of recipients be calculated at run time.

Figure 23. Recipient List Pattern

فارمت گیرااه : ا و روتر کد یر نیلا دریلفر را ود چیا صا رک ارملل کیا. والوه ور این، ود ط ر

ع ل ارکزا آا امت کد لیار ای دریلفت کییاگلا در ی لا اجرا حلمبد ش اا.

4- Splitter

A splitter is a type of router that splits an incoming message into a series of outgoing messages. Each of the outgoing messages contains a piece of the original message. In Apache Camel, the splitter pattern, shown in Figure 24, is implemented by the split()Java DSL command.

Figure 24. Splitter Pattern

نیالا یلا دریلفر را ود یکااااارا نیلا مروج ت زید کیا. یر نیلا : ا و روتر کاد )جاااکییااه( اماااارکیرر

مروج شل ب تکد اا ای نیلا ایک امت.

Page 10: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

10 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

5- Aggregator

The aggregator pattern, shown in Figure 25, enables you to combine a batch of related messages into a single message.

Figure 25. Aggregator Pattern

الگ ا ج ع آورا : اجلیه دیا ود ش ل وراا ترکیب دمرد اا ای نیلا یلا رو ود یس نیلا واحا.

6- Resequencer

The resequencer pattern, shown in Figure 28, enables you to resequence messages according to a sequencing expression. Messages that generate a low value for the sequencing expression are moved to the front of the batch and messages that generate a high value are moved to the back.

Figure 28. Resequencer Pattern

( کییا ولت جد ود رتب) resequenceترتیب مایب دوولره : این الگ ود ش ل اجلیه دیا تل نیلا یل را ور اایا

یس وبلرت )ویلا( ر ال . نیلا یلا ت لیا شااه ول اری کس ود جک یر ب ش اا و نیلا یلا ول اری ولال ود

و ب.

7- Routing Slip

The routing slip pattern, shown in Figure 29, enables you to route a message consecutively through a series of processing steps, where the sequence of steps is not known at design time and can vary for each message. The list of endpoints through which the message should pass is stored in a header field (the slip), which Apache Camel reads at run time to construct a pipeline on the fly.

Page 11: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

11 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

Figure 29. Routing Slip Pattern

یس ماارا راحب روتر امااکی) )الگ ا لغز ااایریلو ( ود شاا ل اجلیه دیا تل یس نیلا ر ال را ای طری

شیلمرد شاه ایات و وراا یر نیلا رفلوت امت. نردای ارملل کییا کد ت ال راحب آا در رحکد طراح

8- Throttler

A throttler is a processor that limits the flow rate of incoming messages. You can use this pattern to protect a target endpoint from getting overloaded. In Apache Camel, you can implement the throttler pattern using the throttle() Java DSL command.

وراار یس نردایااه امات وراا حاود کردا ماروت جریلا نیلا یلا ورودا. ش ل ت اایا ای این الگ کتروت

امرفلده کییا. )مرریزا( غیر یرظره overload حلفظت ای ن ییت یاه ای

9- Delayer

A delayer is a processor that enables you to apply a relative time delay to incoming messages.

یس نردایااه امت کد ش ل را قلدر ملید ود او لل تلمیر ی لا اابت ود نیلا یلا ورودا.

10- Load Balancer

The load balancer pattern allows you to delegate message processing to one of several endpoints, using a variety of different load-balancing policies.

.load-balancing ح ل کردا نردای نیلا ود یک ای چیاین ا طد نلیلا ول امرفلده ای میلمت یلا رک

Page 12: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

12 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

11- Multicast

The multicast pattern, shown in Figure 30, is a variation of the recipient list with a fixed destination pattern, which is compatible with the InOut message exchange pattern. This is in contrast to recipient list, which is only compatible with the InOnly exchange pattern.

Figure 30. Multicast Pattern

الگ ا چیاو ش : یس الگ ا دریلفر ری ع ول صا ثلوت امت کد ول الگ ا نیلا یلا ورودا و مروج ملیگلر

امت.

12- Composed Message Processor

The composed message processor pattern, as shown in Figure 31, allows you to process a composite message by splitting it up, routing the sub-messages to appropriate destinations, and then re-aggregating the responses back into a single message.

Figure 31. Composed Message Processor Pattern

وراا نردای ترکیب نیلا و ت ایس آا. ) ایریلو نیلا یلا ییر ود و مرس ولیگشت ود یس نیلا واحا(

Page 13: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

13 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

13- Scatter-Gather

The scatter-gather pattern, as shown in Figure 32, enables you to route messages to a number of dynamically specified recipients and re-aggregate the responses back into a single message.

Figure 32. Scatter-Gather Pattern

ج ع آورا: شااا ل را قلدر مااالید تل نیلا رمااالا کییا ود تعاادا ای دریلفت کییاگلا ن یل و –الگ ا نراکیاه

. Aggregatorدوولره ولیگشت ود یس نیلا واحا ود ک س

14- Loop

The loop pattern enables you to process a message multiple times. It is used mainly for testing.

الگ ا حک د ش ل را قلدر ملید وراا نردای چیاین ولره نیلا کد و اتلً وراا تات امرفلده ش د.

15- Sampling

A sampling throttler allows you to extract a sample of exchanges from the traffic through a route. It is configured with a sampling period during which only a single exchange is allowed to pass through. All other exchanges will be stopped. By default, the sample period is 1 second.

ت.ام ثلاید ملید ود امر راج ا اد و بلدالت ترافیس روتر. نری د ی لا نیا فرض آا یس ش ل را قلدر

16- Dynamic Router

The Dynamic Router pattern, as shown in Figure 33, enables you to route a message consecutively through a series of processing steps, where the sequence of steps is not known at design time.

Page 14: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

14 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

The list of endpoints through which the message should pass is calculated dynamically at run time. Each time the message returns from an endpoint, the dynamic router calls back on a bean to discover the next endpoint in the route.

Figure 33. Dynamic Router Pattern

الگ ا ن یل شا ل را قلدر مالید ود ایریلو یس نیلا ر ال ای طری یس مرا ای راحب نردای . کد ت ال

ایااات. ا طد نلیلا نیلا ولیا ود یاا رت ن یل در ی لا اجرا حلماابد راحب آا در ی لا طراح شاایلمرد شاااه

ش د. یرولر کد نیلا ای ا طد نلیلا ولیگشت داده ش د، روتر ن یل وراا کش ا طد نلیلا وعاا را یاا یاا.

Page 15: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

15 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

System Management

. رملا نیلا میارس یس اداره و آی ا، اظلرت، وراا میارس ایریت الگ یلا

1- Wire Tap

The wire tap pattern, as shown in Figure 47, enables you to route a copy of the message to a separate tap location, while the original message is forwarded to the ultimate destination.

Figure 47. Wire Tap Pattern

زا در حب جااگلاد اا داشرد ولشیا ، الگ ا وایر ت)، شا ل را قلدر مالید تل یس کر ای نیلا را ود ی رت

.ش د فرمرلده االی صا ود ایک نیلا کد حلل در

2- Smart Proxy

Use a Smart Proxy to store the Return Address supplied by the original requestor and replace it with the address of the Smart Proxy. When the service sends the reply message route it to the original Return Address.

Page 16: Enterprise integration patterns الگوهای روتر پیام رسان

Enterprise Integration Patterns - The Book , by Gregor Hohpe (ISBN-13: 078-5342200683)

16 | P a g e

December 2014 - Persian Translated by : Ahmad MohammadAlizadeh ([email protected])

ول آا جلیگزیی و ایک درم امت ت ماا شااه ورواد ورگشات آدرس ذمیره وراا، ی شا یا نروکاا یس ای

آدرس ایااک ود را آا ااایر نلماا نیلا ماارویس کد ییگل اماارفلده شاا د، ی شاا یا نروکااا آدرس

.فرمرا ولیگشت


Top Related