--- url: "https://www.enterpriseintegrationpatterns.com/patterns/conversation/DynamicDiscovery.html" titulek: "Dynamic Discovery - Enterprise Integration Patterns 2" h1: "" popis: "Enterprise Integration Patterns" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-15 14:53:09" znaku: 7437 slov: 1048 kodovani: "utf-8" sha256: "544f908dec144d128e8f9a592eb6b3ded74833266f45ef0a11d063ae1572532c" --- | | Dynamic Discovery[Conversation Patterns](index.html) » [Discovery](DiscoveryIntro.html) | [Contents](toc.html)[⇐ Prev](DiscoveryIntro.html)[Next ⇒](ParticipantsAdvertise.html) | | --- | --- | --- | A participant wants to initiate a conversation. How can a conversation initiator find a partner when it has no knowledge whatsoever about available partners? Point-to-point communication (see [*Point-to-Point Channel*](/patterns/messaging/PointToPointChannel.html)) requires the initiator to know the conversation partner it wants to communicate with. Communication over [*Publish-Subscribe Channel*](/patterns/messaging/PublishSubscribeChannel.html) allow a sender to broadcast messages to multiple subscribers without the sender having to know the subscribers' identity.Late binding between a conversation initiator and a conversation partner lowers the location coupling between them. However, it also puts the discovery on the critical path to establishing a conversation.Even in the presence of a central lookup service, a new participant has to first establish a connection to the lookup service. This can provide a bootstrap problem.Deploying new services should be easy and involve as little manual administration as possible.*Maintaining a list of available conversation partners is bound to get out of date as new partners appear and existing ones retire.* The consumer broadcasts a query to the network, indicating what kind of service or services it is looking for. All potential providers listen to the query, with the ones who are able and willing to fulfill the request responding. The initiator selects one partner from the responses it receives. The *Dynamic Discovery* conversation involves the following participants: - The *Initiator* starts the *Dynamic Discovery* by broadcasting a *Lookup* message. Based on the received *Response* s it selects a conversation partner and begins the conversation. - Potential *Provider* s listen for lookup message and respond if they are itself with the *Directory* . The process of *Dynamic Discovery* consists of the following steps: 1. *Request* : The *Initiator* sends a service request via a [*Publish-Subscribe Channel*](/patterns/messaging/PublishSubscribeChannel.html) . The *Initiator* has no knowledge of any specific service recipient. 2. *Consider* : Potential conversation partners receive the request and can decide whether to respond or not. 3. *Respond* : If a conversation partner is willing to engage in a conversation it replies with an *Offer* to the *Initiator* , typically via the [*Return Address*](/patterns/messaging/ReturnAddress.html) supplied by the *Requestor* . 4. *Choose* : The *Initiator* collects the *Offer* messages from the potential *Provider* s and decides which one to interact with. 5. *Interact* : The *Initiator* begins a conversation with the chosen partner. The initiator may also announce its decision to the other service candidates to allow them to relinquish potentially allocated resources. The [*Publish-Subscribe Channel*](/patterns/messaging/PublishSubscribeChannel.html) often takes the form of an IP multicast on a local network segment, which has the advantage that only nearby services see the request. This approach avoids flooding the whole network and increases the chances that an initiator finds a nearby conversation partner. Both the *Initiator* and the *Provider*s can apply rules as to whether they want to become conversation partners. These rules can be based on criteria specified by the *Initiator* (e.g. the type of service that is needed) or the state of the *Provider* (e.g., number of clients that are currently being served). When collecting *Offer* messages from *Provider*s, the initiator acts as an [*Aggregator*](/patterns/messaging/Aggregator.html). The *Initiator* has to decide how long to wait for *Offer* messages and how pick a *Provider*. Because the initiator does not know how many potential *Provider*s may respond, the completeness condition typically employs a "first best" or "timeout" strategy. *Dynamic Discovery* particularly well in environments where conversation partners appear and disappear frequently because maintaining a central list of partners is difficult to keep in sync with the reality. *Dynamic Discovery* can also be used to discover a registry, in which case [*Consult Directory*](ConsultDirectory.html) follows *Dynamic Discovery*. Once the *Initiator* has identified a conversation partner, it may use other patterns to establish a conversation. For example, it might need to establish trust with the provider before it wants to begin to exchange information. Because *Dynamic Discovery* establishes a direct connection between initiator without any intermediary, the communicating parties may have to spend more effort establishing a conversation. Broadcasting across the network can be inefficient if initiators frequently look for conversation partners. Therefore, *Dynamic Discovery* works best with long running conversations or stateful conversations that do not require an initiator to rediscover a provider every time. *Initiator*s often cash the result of previous *Dynamic Discovery* conversations, thus reducing network traffic. This implies, though, that information may be out-of-date. Therefore, the *Initiator* has to be prepared that the contacted service is not available. The initial interaction of *Dynamic Discovery* resembles [*Scatter-Gather*](/patterns/messaging/BroadcastAggregate.html). However, [*Scatter-Gather*](/patterns/messaging/BroadcastAggregate.html) is based on a stateless [*Pipes and Filters*](/patterns/messaging/PipesAndFilters.html) model, whereas *Dynamic Discovery* is a stateful conversation. For example, in [*Scatter-Gather*](/patterns/messaging/BroadcastAggregate.html) the initiator and the Aggregator may be completely disconnected entities, whereas in *Dynamic Discovery* responses have to come back to the initiator to be meaningful. ## Example: DHCP Most IP-based networks assign IP addresses dynamically: when a machine joins a network, it is identifiable at the Data Link Layer of the OSI stack by its unique MAC (Media Access Control) address, but does not yet have an IP address needed to address it at the Transport Layer. To manage the assignment of IP addresses while avoiding address collisions, a Dynamic Host Configuration Protocol (DHCP) server issues and tracks IP addresses "leased" to machines on the network. In order to obtain an IP address, though, a new machine has to first discover a DHCP server. DHCP uses UDP broadcast packets to locate a DHCP server. One or more servers respond with an offer for a lease to an IP address. The client accepts one offer and broadcasts its decision so that other DHCP servers can take back their offers. *Dynamic Discovery* is a good choice for the discovery of DHCP servers because IP assignment happens relatively infrequently thanks to leases that often run several days. To manage IP addresses efficiently, DHCP servers [*Lease*](Lease.html) addresses for a limited amount of time. **Related patterns:**[*Aggregator*](/patterns/messaging/Aggregator.html), [*Scatter-Gather*](/patterns/messaging/BroadcastAggregate.html), [*Consult Directory*](ConsultDirectory.html), [*Lease*](Lease.html), [*Pipes and Filters*](/patterns/messaging/PipesAndFilters.html), [*Point-to-Point Channel*](/patterns/messaging/PointToPointChannel.html), [*Publish-Subscribe Channel*](/patterns/messaging/PublishSubscribeChannel.html), [*Return Address*](/patterns/messaging/ReturnAddress.html) ---