Tag Archives: Microservices

[Solved] nacos Error: com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance

2021-12-18 11:39:44.536 ERROR 26756 --- [           main] c.a.c.n.registry.NacosServiceRegistry    : nacos registry, cs-qq-guild register failed...NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='xxxx:8848', endpoint='', namespace='xxxx', watchDelay=30000, logName='', service='xxx', weight=1.0, clusterName='DEFAULT', group='xxx', namingLoadCacheAtStart='false', metadata={appname=xxx, preserved.register.source=SPRING_CLOUD, version=0.0.1}, registerEnabled=true, ip='xxx', networkInterface='', port=5203, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null, failFast=true}},

com.alibaba.nacos.api.exception.NacosException: Request nacos server failed: 
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:279) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.doRegisterService(NamingGrpcClientProxy.java:129) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.registerService(NamingGrpcClientProxy.java:115) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.registerService(NamingClientProxyDelegate.java:95) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:145) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:74) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.7.RELEASE.jar:2.2.7.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:239) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:78) [spring-cloud-starter-alibaba-nacos-discovery-2.2.7.RELEASE.jar:2.2.7.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:138) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:101) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:88) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:165) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.13.RELEASE.jar:2.2.13.RELEASE]
	at com.yzycoc.discord.QqGuildApplication.main(QqGuildApplication.java:33) [classes/:na]
Caused by: com.alibaba.nacos.api.exception.NacosException: Client not connected,current status:STARTING
	at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:655) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:635) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:269) ~[nacos-client-2.0.3.jar:na]
	... 25 common frames omitted

nacos can start normally, but the microservice can’t be registered, resulting in compilation errors
The previous day it worked fine, but today the above error appears in the startup

My side because the address of nacos is localhost:8848 as configured in application.yml
And the address of nacos we started is 198.168.52.12 (why suddenly become this address? I don’t understand)

Solution:

Modify nacos/conf/application.properties file

在这里插入图片描述

2. If it doesn’t work, you can try to delete the nacos cache

Local cache directory default path: ${user.home}/nacos/naming/public

3. If you can’t do it, we recommend uninstalling and reinstalling.

[Solved] java Internal error in the mapping processor java.lang.NullPointerException

Error:

java: Internal error in the mapping processor: java.lang.NullPointerException  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.createManifestUrl(DefaultVersionInformation.java:182)  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.openManifest(DefaultVersionInformation.java:153)  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.getLibraryName(DefaultVersionInformation.java:129)  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.getCompiler(DefaultVersionInformation.java:122)  	
at org.mapstruct.ap.internal.processor.DefaultVersionInformation.fromProcessingEnvironment(DefaultVersionInformation.java:95)  	
at org.mapstruct.ap.internal.processor.DefaultModelElementProcessorContext.<init>(DefaultModelElementProcessorContext.java:50)  
at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:218)  	
at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:156)  	
at org.jetbrains.jps.javac.APIWrappers$ProcessorWrapper.process(APIWrappers.java:109)  	
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  	
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  	
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  	
at java.lang.reflect.Method.invoke(Method.java:498)  	
at org.jetbrains.jps.javac.APIWrappers$1.invoke(APIWrappers.java:213)  	
at org.mapstruct.ap.MappingProcessor.process(Unknown Source)  	
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)  	
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)  
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)  	
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)  	
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)  	
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)  	
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)  	
at com.sun.tools.javac.main.Main.compile(Main.java:523)  	
at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)  	
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)  	
at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:231)  	
at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:501)  	
at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:353)  	
at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:277)  	
at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:231)  	
at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1441)  	
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1100)  	at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1224)  	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1066)  	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:832)  	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:419)  	at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:183)  	at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:132)  	at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:302)  	at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:132)  	at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:219)  	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)  	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)  	at java.lang.Thread.run(Thread.java:748)  

When using MapStruct, idea version 2020.3, an error occurs when building the project: java: Internal error in the mapping processor: java.lang.NullPointerException

Solution:
Setting –>Build,Execution,Deployment –>Compiler –>User-local build add the parameter
-Djps.track.ap.dependencies=false

How to Solve mybatis-plus Paging Plug-in PaginationInnerInterceptor error

Questions

mybatis-plus using PaginationInnerInterceptor paging plugin, when calling the paging query method (****Service.page(new Page(param.getPage(),param.getPageSize()),queryWrapper )) reports the following error:

 2022-07-22 17:07:20.699 [TID: N/A]  WARN 12444 --- [io-18080-exec-1] c.b.m.e.p.i.PaginationInnerInterceptor   : optimize this sql to a count sql has exception, sql:"sql语句略", exception:
net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "," ","
    at line 1, column 191.

Was expecting one of:

    "&"
    "::"
    ";"
    "<<"
    ">>"
    "ACTION"
    "ACTIVE"
    "ALGORITHM"
    "ARCHIVE"
    "ARRAY" 
    ***略****

reason

The paging plugin will default to sql optimization when processing count, and will throw an exception if optimization fails. The sql that cannot be optimized will be downgraded to the non-optimized count method.
The code summary is as follows.
where Select select = (Select) CCJSqlParserUtil.parse(sql); This line of code reports error:

    protected String autoCountSql(IPage<?> page, String sql) {
        if (!page.optimizeCountSql()) {
            return lowLevelCountSql(sql);
        }
        try {
            Select select = (Select) CCJSqlParserUtil.parse(sql);
            **************Optimization Logic*********************
            return select.toString();
        } catch (JSQLParserException e) {
            // Unable to optimize the use of the original SQL
            logger.warn("optimize this sql to a count sql has exception, sql:\"" + sql + "\", exception:\n" + e.getCause());
        } catch (Exception e) {
            logger.warn("optimize this sql to a count sql has error, sql:\"" + sql + "\", exception:\n" + e);
        }
        return lowLevelCountSql(sql);
    }

Solution:

Add the following codes before your codes:

if (!page.optimizeCountSql()) {
return lowLevelCountSql(sql);
}

just set optimizeCountSql to false, as follows

Page page = new Page(param.getPage(),param.getPageSize()),queryWrapper)
page.setOptimizeCountSql(false);

You can also redefine a class to inherit Page, and set optimizeCountSql default to =false

 

[Solved] ClickHouse Error: Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): fai

1. Preparation

First, I need to create a table and write the corresponding fields in it:

create table t_order_mt(
 id UInt32,
 sku_id String,
 total_amount Decimal(16,2),
 create_time Datetime
) engine =MergeTree
 partition by toYYYYMMDD(create_time)
 primary key (id)
 order by (id,sku_id);

Next, you need to insert the corresponding data into it:

insert into t_order_mt values
(101,'sku_001',1000.00,'2020-06-01 12:00:00') ,
(102,'sku_002',2000.00,'2020-06-01 11:00:00'),
(102,'sku_004',2500.00,'2020-06-01 12:00:00'),
(102,'sku_002',2000.00,'2020-06-01 13:00:00'),
(102,'sku_002',12000.00,'2020-06-01 13:00:00'),
(102,'sku_002',600.00,'2020-06-02 12:00:00');

2. Error display

When I execute select * from table_name, the following problems may occur:

Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): failed at position 54 (end of query) (line 1, col 54): ;


 FORMAT JSON . . (SYNTAX_ERROR) (version 21.11.6.7 (official build))

3. Solution

You only need to end the sentence after the corresponding sentence; Change to:

select * from t_order_mt;;

Results

 

[Solved] failed to req API:localhost:8848/nacos/v1/ns/instance. code:500 msg: java.net.ConnectException

1. Error Messages
nacos connect error:

2022-03-23 10:06:48 |ERROR |main |SpringApplication.java:826 |org.springframework.boot.SpringApplication |Application run failed
java.lang.IllegalStateException: failed to req API:/nacos/v1/ns/instance after all servers([localhost:8848]) tried: failed to req API:localhost:8848/nacos/v1/ns/instance. code:500 msg: java.net.ConnectException: Connection refused: connect
    at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:467)
    at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:389)
    at com.alibaba.nacos.client.naming.net.NamingProxy.registerService(NamingProxy.java:191)
    at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:207)
    at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:64)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:239)
    at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:76)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:138)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:101)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:88)
    at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:165)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at com.atguigu.guli.service.edu.ServiceEduApplication.main(ServiceEduApplication.java:15)

 

2. Solution
1.Check whether nacos is open
2.Check whether nacos is open properly
3.  nacos and eureka are not the same, eureka is part of the project, nacos is more like a partner relationship.

         ,--.
       ,--.'|
   ,--,:  : |                                         
,`--.'`|  ' :                       ,---.               
|   :  :  | |                      '   ,'\   .--.--.   
:   |   \ | :  ,--.--.     ,---. / /  |//   '   
|   : '  '; |/      \  /    \.   ; ,. :|  :  /`./   
'   ' ;.    ;.--.  .-. |/  /''   | |: :|  :  ;_
|   | | \   | \__\/: . ..    '/'   | .; : \  \    `.      
'   : |  ; .' ," .--.; |'   ; :__|   :    |  `----.   \
|   | '`--' // ,.  |'   | '.'|\   \ // /`--'  /
'   : |     ;  :   .'   \   :    : `----'  '--'.     /
;   |.'     |  ,     .-./\   \ /           `--'---'
'---'        `--`---'     `----'

4. If Nacos starts normally, restart the project, or not

(1) Check annotation @enablediscoveryclient

(2) Check configuration file

# Note the space position
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848 # nacos server location

Opentelemetry + Jaeger Python Version Cross Service Call Example

Opentelemetry Python version cross service invocation example

When calling opentelemetry across services, you need to import opentelemetry-instrumentation-requests, and then use request to cross service requests. (note that aiohttp-client should be used if it is asynchronous)
I use Jaeger on the server, which is deployed directly through the docker of all-in-one. The code is as follows:

docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -p 5775:5775/udp \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 14250:14250 \
  -p 14268:14268 \
  -p 14269:14269 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.32

After starting Jaeger, visit the following page: http://localhost:16686

Python needs to start two services to demonstrate cross service invocation. The framework I use is fastapi, so I need to install opentelemetry-instrumentation-fastapi
call service 1 by service 2
Service 1:

import fastapi
from opentelemetry import trace
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from fastapi import Body
from pybase.lib.tracer.jaeger_ import register_to_jaeger
from pydantic import BaseModel

app = fastapi.FastAPI()


class UserInfo(BaseModel):
    name: str


tracer = trace.get_tracer(__name__)


@app.post("/server")
async def server(userinfo: str = Body(...), name: str = Body(..., )):
    return {"message": f"hello {userinfo},{name}"}



FastAPIInstrumentor.instrument_app(app)
if __name__ == '__main__':
    register_to_jaeger("fastapi-jaeger-server", "localhost")
    import uvicorn

    uvicorn.run(app,port=8001)

Service 2

import fastapi
import requests
from opentelemetry import trace
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from fastapi import Body
from opentelemetry.instrumentation.requests import RequestsInstrumentor
RequestsInstrumentor().instrument()
from pybase.lib.tracer.jaeger_ import register_to_jaeger
from pydantic import BaseModel

app = fastapi.FastAPI()


class UserInfo(BaseModel):
    name: str


tracer = trace.get_tracer(__name__)


@app.post("/foobar")
async def foobar(userinfo: str = Body(...), name: str = Body(..., )):
    with tracer.start_as_current_span("foo"):
        with tracer.start_as_current_span("bar"):
            with tracer.start_as_current_span("baz"):
                print("Hello world from OpenTelemetry Python!")
    return {"message": f"hello {userinfo},{name}"}
@app.post("/foobar2")
async def foobar2(userinfo: str = Body(...), name: str = Body(..., )):
    return {"message": f"hello {userinfo},{name}"}

@app.post("/client")
def client(userinfo: str = Body(...), name: str = Body(..., )):

    res=requests.post("http://127.0.0.1:8001/server",json={
        "userinfo":userinfo,"name":name
    })
    return res.json()


FastAPIInstrumentor.instrument_app(app)
if __name__ == '__main__':
    register_to_jaeger("fastapi-jaeger", "localhost")
    import uvicorn

    uvicorn.run(app)

A function that depends on register_ to_ jaeger:

from opentelemetry import trace
from opentelemetry.exporter.jaeger.thrift import JaegerExporter
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor


def register_to_jaeger(service_name: str, jaeger_host: str, jaeger_port: int = 6831):
    """
    Register the service to jaeger so that tracer-related information can be sent to the jaeger server
    Args:
        service_name: the registered service name
        jaeger_host: jaeger address
        jaeger_port:

    Returns: TracerProvider

    """
    provider = TracerProvider(
        resource=Resource.create({SERVICE_NAME: service_name})
    )
    trace.set_tracer_provider(
        provider
    )

    # create a JaegerExporter
    jaeger_exporter = JaegerExporter(
        agent_host_name=jaeger_host,
        agent_port=jaeger_port,
    )

    # Create a BatchSpanProcessor and add the exporter to it
    span_processor = BatchSpanProcessor(jaeger_exporter)

    # add to the tracer
    trace.get_tracer_provider().add_span_processor(span_processor)

Then execute:

curl -X 'POST' \
  'http://127.0.0.1:8000/client' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "userinfo": "string",
  "name": "string"
}'

You can get the following results:
if you have any questions, please correct them.

[Solved] docker Commands Execute Error: Segmentation fault

If you execute any docker command, you will report an error segmentation fault. There have been no similar errors when using docker before. After troubleshooting, it was found that the available memory was only 110m. It was speculated that the memory was not enough, so the command to clean the memory was executed, but the parameters were changed to 1, 2 and 3, which could not clean the memory.

sync
echo 1 > /proc/sys/vm/drop_caches

The solution is found on GitHub. First enter

sysctl vm.overcommit_memory

The output is 0, and then change the parameters

sysctl vm.overcommit_memory=1

At this time, the application that occupies a lot of memory has been restarted automatically. If not, execute the above cleaning command.

Spring cloud remote connect Nacos error [How to Solve]


Problem description

Spring cloud Alibaba micro service architecture is used, and Nacos is used in the service discovery and configuration center

At the beginning, Nacos was started locally, and everything was normal,

After Nacos is migrated to the cloud, change the Nacos address in the configuration file

The gateway service reports an error java.net.connectexception: no available server, because it is always connected to localhost:8848 .

The console outputs the following screenshot:

Cause location

Because the parent POM dependency is imported:

spring-cloud-starter-Alibaba-Nacos-config and spring-cloud-starter-Alibaba-Nacos-discovery

In local development, items such as testing, registration and discovery are configured in application.yml, the central configuration file bootstrap.properties is not created

Springboot automation configuration defaults to localhost:8848 , so there is no problem with the local environment.

Solution:

Remove useless dependencies (if nacos-config is not used, remove spring-cloud-starter-alibaba-nacos-config dependencies)

[Solved] nacos Error: Client not connected,current status:STARTING,StatusRuntimeException

Nacos client connection operation 9848 grpc connection error of Nacos 2.0

After Nacos Server 2.0

Nacos version 2.0 adds a new gRPC communication method compared to 1.X, so 2 additional ports are needed. The new ports are automatically generated by performing a certain offset from the configured master port (server.port).
Port Offset from the master port Description
9848 1000 Client gRPC request server port for clients to initiate connections and requests to the server
9849 1001 Server-side gRPC request server port, used for synchronization between services, etc.

After Nacos client 2.0 is connected through grpc, you cannot use Nacos server version below 2.0

serverInfo.getServerPort() + rpcPortOffset() Port offset 1000
Perform serverCheck operation 
Report an error.
java.util.concurrent.ExecutionException: com.alibaba.nacos.shaded.io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
Error: RpcClient currentConnection is null
Caused by: ErrCode:-401, ErrMsg:Client not connected,current status:STARTING

Solution: use a lower version of Nacos client

[Solved] Spring cloud introduces zuul dependency error

When creating the zuul project, I found that spring cloud routing does not have zuul

and then directly click next. I think it is possible to introduce zuul dependency by directly writing dependency code in POM file
then I added the following dependencies to the POM file:

   <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
            <version>2.2.10.RELEASE</version>
        </dependency>

Then add @enablezuulproxy
to the startup class. Click Startup and find that an error is reported
Solution:
①: configure version and add & lt; spring-cloud.version>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>2021.0.0-RC1</spring-cloud.version>
    </properties>

②: add unified version configuration

  <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

③: add warehouse configuration

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

Method ①, ② and ③ seem to be indispensable, otherwise it will not start.

(in fact, the spring boot version conflicts with the spring cloud version)
we can click the zuul dependency package to see that it contains the starter of spring boot
therefore, we can directly cancel the parent tag so that it does not introduce parent dependency

however, I don’t think it’s good to cancel the parent dependency directly. After all, there are few introductions, and there is no need to consider the conflict of versions. Therefore, in order not to remove the parent tag, we can introduce the version dependency that does not conflict between spring boot and spring cloud.

Attach the complete POM configuration:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>cn.itcast.zuul</groupId>
    <artifactId>itcast-zuul</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>itcast-zuul</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>


        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
    </dependencies>

</project>


[Solved] renren-fast Startup Error: Error creating bean with name ‘scheduleJobController‘

When doing the gulimall mall project, start Ren fast to report an error in the background. The error information is as follows:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scheduleJobController': Unsatisfied dependency expressed through field 'scheduleJobService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduleJobService': Invocation of init method failed; nested exception is io.renren.common.exception.RRException: 获取定时任务CronTrigger出现异常
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)

Cause analysis: beans cannot be created or loaded. The problem is generally in configuration

Solution steps:
1. Check dao tier, service tier, controller tier is annotated or not?

2. When the annotation of Dao tier, service tier and controller tier is complete, check whether the corresponding package is added to the package scanning for these annotations. If not, add it (generally check in the spring configuration file)

3. Check the corresponding YML and properties files, or check whether the database SQL is executed normally

The solution to this problem: delete the contents of the current database and re-execute the SQL file