8

मैं कैसे पता लगा सकता हूं कि GetAccounts को ट्रिगर करने के लिए मुझे किस एंडपॉइंट का अनुरोध करना चाहिए?सेवा कपड़े पर एप्लिकेशन कैसे ब्राउज़ करें?

मैं अपने स्थानीय क्लस्टर पर चल रहे दो आवेदन मिल गया है: enter image description here

enter image description here

कपड़े/सेवा निम्नलिखित विन्यास के साथ एक वेब एपीआई अनुप्रयोग है:

internal sealed class Web : StatelessService 
    { 
     public Web(StatelessServiceContext context) 
      : base(context) 
     { 
     } 

     /// <summary> 
     ///  Optional override to create listeners (like tcp, http) for this service instance. 
     /// </summary> 
     /// <returns>The collection of listeners.</returns> 
     protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() 
     { 
      return new[] 
      { 
       new ServiceInstanceListener(serviceContext => new OwinCommunicationListener(Startup.ConfigureApp, 
        serviceContext, ServiceEventSource.Current, "ServiceEndpoint")) 
      }; 
     } 
    } 

स्टार्टअप को इस प्रकार कॉन्फ़िगर किया गया है:

public static class Startup 
{ 
    // This code configures Web API. The Startup class is specified as a type 
    // parameter in the WebApp.Start method. 

    public static void ConfigureApp(IAppBuilder appBuilder) 
    { 
     // Configure Web API for self-host. 
     var config = new HttpConfiguration(); 
     //config.Routes.MapHttpRoute(
     // name: "DefaultApi", 
     // routeTemplate: "api/{controller}/{id}", 
     // defaults: new { id = RouteParameter.Optional } 
     //); 
     config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); 
     config.MapHttpAttributeRoutes(); 
     var container = new UnityContainer(); 
     container.RegisterType<IAccountService, AccountService>(new HierarchicalLifetimeManager()); 
     config.DependencyResolver = new UnityResolver(container); 

     appBuilder.UseWebApi(config); 
    } 
} 

और अंत में सेवा प्रकट:

<?xml version="1.0" encoding="utf-8"?> 

<ServiceManifest Name="WebPkg" 
       Version="1.0.0" 
       xmlns="http://schemas.microsoft.com/2011/01/fabric" 
       xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <ServiceTypes> 
    <!-- This is the name of your ServiceType. 
     This name must match the string used in RegisterServiceType call in Program.cs. --> 
    <StatelessServiceType ServiceTypeName="WebType" /> 
    </ServiceTypes> 

    <!-- Code package is your service executable. --> 
    <CodePackage Name="Code" Version="1.0.0"> 
    <EntryPoint> 
     <ExeHost> 
     <Program>removed...........Accounts.Web.exe</Program> 
     <WorkingFolder>CodePackage</WorkingFolder> 
     </ExeHost> 
    </EntryPoint> 
    </CodePackage> 

    <!-- Config package is the contents of the Config directoy under PackageRoot that contains an 
     independently-updateable and versioned set of custom configuration settings for your service. --> 
    <ConfigPackage Name="Config" Version="1.0.0" /> 

    <Resources> 
    <Endpoints> 
     <!-- This endpoint is used by the communication listener to obtain the port on which to 
      listen. Please note that if your service is partitioned, this port is shared with 
      replicas of different partitions that are placed in your code. --> 
     <Endpoint Protocol="http" Name="ServiceEndpoint" Type="Input" /> 
    </Endpoints> 
    </Resources> 
</ServiceManifest> 

और मेरे नियंत्रक:

[HttpGet] 
    [Route("accounts", Name = "GetAccounts")] 
    public async Task<IHttpActionResult> GetAccounts(){//dostuff} 

मुझे कैसे पता चलेगा कि क्या endpoint मैं आदेश GetAccounts को गति प्रदान करने में का अनुरोध किया जाना चाहिए?

उत्तर

2

मुझे लगता है कि यह वेब एपी बाहरी दुनिया से अवगत कराया गया है? आपके द्वारा होस्ट करने के लिए उपयोग की जाने वाली स्टेटलेस सेवा में डायनामिक पोर्ट सक्षम है। बाह्य सामना सेवाओं के लिए इसे एक निश्चित बंदरगाह देना सर्वोत्तम है।

सेवा मैनिफ़ेस्ट फ़ाइल में आप अंत बिंदु परिभाषा पोर्ट संख्या जोड़ सकते हैं:

<Endpoint Protocol="http" Name="ServiceEndpoint" Type="Input" Port="80"> 

देखें अधिक जानकारी के लिए this link देखें।

एक बार जब आप portnumber आप http://localhost:80/api/[controller]/accounts

पर वेब एपीआई का उपयोग कर सकते फिर आप एक्सप्लोरर में वास्तविक पोर्ट नंबर देखने के लिए आप डायनामिक पोर्ट का उपयोग कर रहे हैं या नहीं कर सकते हैं।

इस तरह से अपनी सेवा के नीचे एक नोड के लिए endpoint पोर्ट संख्या ब्राउज़ देखने के लिए: enter image description here

(? दाईं ओर endpoint देखें)

ध्यान दें कि endpoint एक के आईपी शामिल है विशिष्ट नोड, आपको क्लस्टर के आईपी या एफक्यूडीएन की आवश्यकता है। लेकिन अब के लिए यह ठीक लगता है क्योंकि आप localhost का उपयोग कर रहे हैं।

+0

पीटर, इतना धन्यवाद तुम्हारी मदद के लिए। मैंने ठीक वही किया जैसा आपने सुझाव दिया था, लेकिन कोई नहीं जाना: https://lh3.googleusercontent.com/-QqFCDujEYys/WSiH1wpAaSI/AAAAAAAAC3E/iijNazjURZw3TCJQHSFH1UKovtYErkHrwCHM/s0/2017-05-26_14-53-42.gif –

+0

@MeggieLuski त्रुटि इंगित करता है कि पहले से ही पोर्ट 80 पर कुछ और सुन रहा है। इसे कैब काम देखने के लिए पहले पोर्ट नंबर 81 को बदलने का प्रयास करें और फिर उस अन्य प्रक्रिया को देखें। क्या आप आईआईएस या कुछ स्थानीयहोस्ट पर चल रहे हैं? –

+0

मैं 81, 82, 83 आदि में बदल गया हूं, और एक ही परिणाम। –

4

गैर-स्थानीय क्लस्टर पर आप reverse proxy का उपयोग कर सकते हैं। एक रिवर्स प्रॉक्सी आपको गतिशील बंदरगाहों का उपयोग करने की अनुमति देता है (जैसा कि आपके .gif में दिखाया गया है)। रिवर्स प्रॉक्सी का उपयोग करते समय आप अपनी सेवा को अपने रिवर्स प्रॉक्सी के पोर्ट नंबर से कॉल कर सकते हैं। आपके उदाहरण में सेवा के साथ कॉल किया जाएगा: http://clusterAddress:19081/Service/Web/api/controller/accounts/GetAccounts

4

सेवा फैब्रिक में, एक सेवा सेवा फैब्रिक क्लस्टर में कहीं भी चलती है, आमतौर पर कई वीएम में वितरित की जाती है। इसे सेवा के मालिक द्वारा या स्वचालित रूप से सेवा फैब्रिक द्वारा, एक स्थान से दूसरे स्थान पर ले जाया जा सकता है। सेवाएं किसी विशेष मशीन या पते से स्थिर रूप से बंधी नहीं होती हैं।

एक सेवा फैब्रिक एप्लिकेशन आम तौर पर कई अलग-अलग सेवाओं से बना होता है, जहां प्रत्येक सेवा एक विशेष कार्य करती है। ये सेवाएं एक पूर्ण कार्य करने के लिए एक-दूसरे के साथ संवाद कर सकती हैं, जैसे वेब अनुप्रयोग के विभिन्न हिस्सों को प्रस्तुत करना। ऐसे क्लाइंट एप्लिकेशन भी हैं जो सेवाओं से जुड़ते हैं और संवाद करते हैं।

उदाहरण के लिए, पोर्ट 80 पर बाहरी यातायात को स्वीकार करने के लिए, निम्नलिखित चीजें कॉन्फ़िगर की जानी चाहिए: पोर्ट 80 पर सुनवाई वाली एक सेवा लिखें। सेवा की सेवा में पोर्ट 80 कॉन्फ़िगर करें Manifest.xml और सेवा में श्रोता खोलें , उदाहरण के लिए, एक स्वयं-होस्टेड वेब सर्वर।

एक्सएमएल

<Resources> 
    <Endpoints> 
     <Endpoint Name="WebEndpoint" Protocol="http" Port="80" /> 
    </Endpoints> 
</Resources> 

सी #

class HttpCommunicationListener : ICommunicationListener 
    { 
     ... 

     public Task<string> OpenAsync(CancellationToken cancellationToken) 
     { 
      EndpointResourceDescription endpoint = 
       serviceContext.CodePackageActivationContext.GetEndpoint("WebEndpoint"); 

      string uriPrefix = $"{endpoint.Protocol}://+:{endpoint.Port}/myapp/"; 

      this.httpListener = new HttpListener(); 
      this.httpListener.Prefixes.Add(uriPrefix); 
      this.httpListener.Start(); 

      string publishUri = uriPrefix.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); 
      return Task.FromResult(publishUri); 
     } 

     ... 
    } 

class WebService : StatelessService 
    { 
     ... 

     protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() 
     { 
      return new[] { new ServiceInstanceListener(context => new HttpCommunicationListener(context))}; 
     } 

     ... 
    } 

इस दस्तावेज़ को कैसे साथ और सेवा कपड़ा में अपनी सेवाओं के बीच संचार स्थापित करने के लिए की चर्चा:

Connect and communicate with services in Service Fabric

+0

ऐप मेनिफेस्ट से servicemanifest में संसाधन अनुभाग को ओवरराइड करना संभव है? –

संबंधित मुद्दे