|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package main |
| 19 | + |
| 20 | +import ( |
| 21 | + "context" |
| 22 | +) |
| 23 | + |
| 24 | +import ( |
| 25 | + "dubbo.apache.org/dubbo-go/v3" |
| 26 | + "dubbo.apache.org/dubbo-go/v3/config_center" |
| 27 | + _ "dubbo.apache.org/dubbo-go/v3/imports" |
| 28 | + |
| 29 | + "github.com/dubbogo/gost/log/logger" |
| 30 | +) |
| 31 | + |
| 32 | +import ( |
| 33 | + greet "github.com/apache/dubbo-go-samples/config_center/apollo/proto" |
| 34 | +) |
| 35 | + |
| 36 | +// Apollo Configuration Center Parameters |
| 37 | +const ( |
| 38 | + apolloMetaAddress = "127.0.0.1:8080" |
| 39 | + apolloAppID = "SampleApp" |
| 40 | + apolloCluster = "default" |
| 41 | + apolloNamespace = "dubbo.yml" |
| 42 | +) |
| 43 | + |
| 44 | +func main() { |
| 45 | + // Initialize client using configuration center |
| 46 | + ins, err := dubbo.NewInstance( |
| 47 | + dubbo.WithConfigCenter( |
| 48 | + config_center.WithApollo(), |
| 49 | + config_center.WithAddress(apolloMetaAddress), |
| 50 | + config_center.WithNamespace(apolloNamespace), |
| 51 | + config_center.WithDataID(apolloNamespace), |
| 52 | + config_center.WithAppID(apolloAppID), |
| 53 | + config_center.WithCluster(apolloCluster), |
| 54 | + //config_center.WithFileExtProperties(), |
| 55 | + ), |
| 56 | + ) |
| 57 | + if err != nil { |
| 58 | + logger.Fatal(err) |
| 59 | + } |
| 60 | + |
| 61 | + // Configure client parameters |
| 62 | + cli, err := ins.NewClient() |
| 63 | + if err != nil { |
| 64 | + logger.Fatal(err) |
| 65 | + } |
| 66 | + |
| 67 | + // Create service client |
| 68 | + svc, err := greet.NewGreetService(cli) |
| 69 | + if err != nil { |
| 70 | + logger.Fatal(err) |
| 71 | + } |
| 72 | + |
| 73 | + // Call remote service |
| 74 | + resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "Apollo"}) |
| 75 | + if err != nil { |
| 76 | + logger.Error(err) |
| 77 | + } |
| 78 | + logger.Infof("Greet response: %s", resp) |
| 79 | +} |
0 commit comments