spring-boot整合consul随记-程序员宅基地

技术标签: consul  

1.创建父项目。

首先创建一个maven项目,使用的spring-boot版本为2.3.5.RELEASE,对应的spring cloud版本为Hoxton.RELEASE。我们如果不知道该怎么选版本怎么办呢?可以参考如下版本选取的对照参表:

Release Train Spring Boot Generation
2023.0.x aka Leyton 3.2.x
2022.0.x aka Kilburn 3.0.x, 3.1.x (Starting with 2022.0.3)
2021.0.x aka Jubilee 2.6.x, 2.7.x (Starting with 2021.0.3)
2020.0.x aka Ilford 2.4.x, 2.5.x (Starting with 2020.0.3)
Hoxton 2.2.x, 2.3.x (Starting with SR5)
Greenwich 2.1.x
Finchley 2.0.x
Edgware 1.5.x
Dalston 1.5.x

确定好自己想要的版本后,父maven配置如下依赖。

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>mydubbo</groupId>
  <artifactId>dubbo-parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <modules>
    <module>consul-dev</module>
  </modules>

  <name>dubbo-parent</name>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>11</java.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
    <apache-curator.version>5.2.0</apache-curator.version>
    <junit.version>3.8.1</junit.version>
  </properties>


  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.5.RELEASE</version>
    <relativePath/>
  </parent>

  <dependencyManagement>
    <dependencies>
      <!--spring boot的bom依赖,如果使用parent 那么就不需要在这里面用import导入了-->
      <!--<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring-boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>-->

      <!--spring cloud的bom依赖,要和spring boot版本对应上才行-->
      <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>



  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <version>3.2.3</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>


</project>

2.创建子模块。

我们在这个父项目里创建一个子模块consul-dev,如果使用idea的话,就在父项目上,右键new module,完善模块信息后就创建出来了,模块会配置在上面<modules>标签中。

3.配置POM依赖。

在子模块的pom文件中引用依赖如下。

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>dubbo-parent</artifactId>
        <groupId>mydubbo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>consul-dev</artifactId>


    <dependencies>
        <!--spring-boot-starter-actuator 是Spring Boot的一个Starter模块,它提供了一系列用于监控和管理Spring Boot应用的端点(endpoints),使得开发者可以方便地对运行中的应用进行健康检查、指标监控、审计跟踪、HTTP跟踪、环境信息查看、 Beans信息查看等操作。-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!--spring boot,parent里的版本-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!--consul 的监听服务,来源于spring cloud模块-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        </dependency>
        <!--测试模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--web模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>


</project>

为啥上面没写版本号呢?因为我们依赖了父模块,在父模块中各组件版本已经定义好了。我们在这里引用了 spring-boot-starter-actuator健康监控模块,使用spring-boot-starter引入了spring boot(使用spring boot的starter相信你懂的,不懂的可以搜一下这个面试可能会问),引入了spring-cloud-starter-consul-discovery(这个是spring cloud的组件,用来注册consul服务注册发现),使用spring-boot-starter-web引入了web模块(为我们提供web功能)等,由此可见spring-boot还是很方便的,作为一个copy工程师,只要发现是有,想用啥拿来就用。

4.配置consul相关参数。

在子模块的resources中创建一个application.yml(或者application.properties)文件,配置如下:

spring:
  application:
    name: consul-dev #定义此服务名称
  cloud:
    consul:
      host: 124.223.114.XXX #consul注册地址
      port: 8500 #consul注册地址的端口,8500是默认端口
      discovery:
        enabled: true #启用服务发现
        instance-id: ${spring.application.name}-01 # 注册实例id(必须唯一)
        service-name: ${spring.application.name} # 引用上面的服务名称
        port: ${server.port} # 服务端口
        prefer-ip-address: true #是否使用ip地址注册
        ip-address: ${spring.cloud.client.ip-address} # 服务请求ip
        register: true #启用自动注册
        deregister: true #停服务自动取消注册
        health-check-url: http://XXXXXX.vicp.fun/actuator/health # 健康检查
        health-check-interval: 10s #健康检查时间10秒
        health-check-critical-timeout: 5s #健康超时时间5秒

server:
  port: 8080 #我们服务的端口地址

 health-check-url: http://XXXXXX.vicp.fun/actuator/health # 为健康检查地址,这个会注册给consul告诉其健康检查的地址和时间间隔。我的consul是用docker部署在远程个人服务器上的,你们可以换成你自己的地址。

5.服务启动类。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
public class DevConsul {
    public static void main(String[] args) {
        SpringApplication.run(DevConsul.class, args);
    }
}

 使用此@EnableDiscoveryClient注解允许此项目进行服务注册。

6.自定义的web服务类

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestControler {

    @GetMapping("/")
    public String home() {
        return "Hello World!";
    }
}

7.consul相关。

我的consul是用docker部署到Linux服务器上的,你自己测试的时候可以本地下载个windows版本的。下载地址:Install | Consul | HashiCorp Developer

我自己用的是latest最新版,你可以选择你喜欢的版本。

 启动consul,然后再启动你的服务 ,就可以看到服务已经注册上了。如果你是测试环境且没用docker可以类似这样启动:consul agent -dev -client=0.0.0.0 -datacenter=mydc -node=myagent -ui -log-level=info -grpc -bind=192.168.1.100 -disable-host-node-id

  • consul agent: 启动Consul代理服务,它是Consul集群的核心组成部分,负责健康检查、KV存储、服务发现等功能。

  • -dev: 开启开发者模式(Development Mode)。在开发模式下,Consul会运行在一个单节点集群中,无需加入其他节点即可快速启动和测试Consul的功能,数据保存在内存中,不会持久化到磁盘,重启后数据会丢失。

  • -client=0.0.0.0: 设置Consul监听客户端请求的地址。这里设置为0.0.0.0表示Consul会在所有网络接口上监听客户端的HTTP和DNS请求。

  • -datacenter=mydc: 指定数据中心名称为mydc。在Consul中,数据center是用来组织节点的逻辑单元,同一数据中心内的节点之间可以直接通信。

  • -node=myagent: 指定当前Consul节点的名称为myagent。每个节点都需要一个唯一的名称以便于识别。

  • -ui: 开启内置的Web UI界面,允许用户通过浏览器访问Consul的可视化管理界面,默认监听8500端口。

  • -log-level=info: 设置日志级别为info。Consul的日志可以根据这个参数设定详细程度,info表示记录一般信息级别的日志。

  • -grpc: 启用gRPC支持。gRPC是Google开发的一种高性能、开源和通用的RPC框架,Consul使用gRPC来提供更高效的服务间通信。

  • -bind=192.168.1.100: 设置Consul代理绑定的IP地址,所有网络通信都会通过这个地址进行。在这里,Consul将通过192.168.1.100地址对外提供服务。

  • -disable-host-node-id: 禁止使用主机名作为节点ID。在默认情况下,Consul会尝试使用主机名和MAC地址生成一个唯一节点ID,这个选项禁止了这种行为,通常在需要手动指定节点ID时使用。

刚好对应上我们配置里的服务名和实例名。

 8.结合feign进行远程调用。

        我们可以再创建一个consul-test服务,通过open-feign用来调用consul-dev。那么open-feign和feign有啥区别呢?其实open-feign是feign的增强版本:

  1. Spring Cloud 集成

    • Feign:最初是由 Netflix 开发的声明式 HTTP 客户端库,其本身并不直接支持 Spring Cloud 的全部特性。
    • OpenFeign:是基于 Feign 的扩展版本,由 Spring Cloud 团队进行了专门的封装和增强,使得它可以无缝地与 Spring Cloud 生态系统集成,尤其是 Spring MVC 注解和 Spring Boot 配置。
  2. 注解支持

    • Feign:原生 Feign 支持自身的注解来描述服务调用接口,但不一定能直接识别和利用 Spring MVC 的注解,如 @RequestMapping 等。
    • OpenFeign:除了支持 Feign 自身的注解外,还支持 Spring MVC 标准注解,开发者可以直接使用这些注解来定义 RESTful API 调用,简化了开发流程。
  3. 依赖管理与启动器

    • Feign:单独使用时,需要自行管理和配置相关的依赖,如 Ribbon 进行负载均衡。
    • OpenFeign:作为 Spring Cloud 的一部分,提供了 spring-cloud-starter-openfeign 依赖启动器,方便在 Spring Boot 项目中快速引入和使用,且集成了 Ribbon 或者 Spring Cloud LoadBalancer 用于服务发现和负载均衡。
  4. 扩展性和配置

    • OpenFeign 提供了更丰富的配置选项,比如可以通过 Spring Boot 的配置文件轻松配置超时、重试等策略,并且可以更好地与 Spring Cloud 的其他组件如 Hystrix、Zuul、Eureka 等配合,实现服务熔断、路由等功能。

创建的新服务依赖如下:增加了spring-cloud-starter-openfeign(用来远程调用) 和 spring-cloud-starter-netflix-hystrix(断路器) 组件。

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>dubbo-parent</artifactId>
        <groupId>mydubbo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>consul-test</artifactId>

    <dependencies>

        <!--spring-boot-starter-actuator 是Spring Boot的一个Starter模块,它提供了一系列用于监控和管理Spring Boot应用的端点(endpoints),使得开发者可以方便地对运行中的应用进行健康检查、指标监控、审计跟踪、HTTP跟踪、环境信息查看、 Beans信息查看等操作。-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!--spring boot,parent里的版本-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!--consul 的监听服务,来源于spring cloud模块-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        </dependency>
        <!--测试模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--web模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>

       
    </dependencies>


</project>

添加如下yml配置,添加断路器并配置超时时间。

spring:
  application:
    name: consul-test
  #  profiles:
  #    active: dev
  cloud:
    consul:
      host: 124.223.114.XXX
      port: 8500
      discovery:
        enabled: true
        instance-id: ${spring.application.name}-01 # 注册实例id(必须唯一)
        service-name: ${spring.application.name} # 服务名称
        port: ${server.port} # 服务端口
        prefer-ip-address: true #是否使用ip地址注册
        ip-address: http://XXXXXXX1.goho.co # 服务请求ip
        register: true
        deregister: true
        health-check-url: http://XXXXXXX1.goho.co/demo/actuator/health # 健康检查
        health-check-interval: 10s
        health-check-critical-timeout: 5s

server:
  port: 8081
  servlet:
    context-path: /demo

# 熔断器
feign:
  hystrix:
    enabled: true
  httpclient:
    connection-timeout: 3000

主启动类增加两个注解@EnableCircuitBreaker (启用断路器)和@EnableFeignClients(启用feign)。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableFeignClients(basePackages = {"com.test.api"})
public class TestConsul {
    public static void main(String[] args) {
        SpringApplication.run(TestConsul.class, args);
    }
}

定义一个接口,设置feign要访问的服务名和url(如果在你配了正确的host地址映射的情况下,url不必需),添加一个失败兜底的类TestFallbackOne。

import com.test.fallback.TestFallbackOne;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(value = "consul-dev",
        url="http://XXXXX.vicp.fun",fallback = TestFallbackOne.class ) // 替换为在Eureka或Consul等注册中心注册的服务名
public interface DemoService {
    @GetMapping("/sayHello/{name}")
    String sayHello(@PathVariable("name") String name);

}
@Component
public class TestFallbackOne implements DemoService {
    @Override
    public String sayHello(String name) {
        return name + "熔断了";
    }

}

在consul-dev服务里增加相应的controller和DemoService接口,注意了这里的DemoService要和consul-test的DemoService要访问的方法保持一致,当然也可以把它俩的接口抽出来单独放在一个模块里维护,这样开发着更方便。

@RestController
public class TestControler {

    @Resource
    private DemoService demoService;

    @GetMapping("/sayHello/{name}")
    public String sayHello(@PathVariable("name") String name) {
        return demoService.sayHello(name);
    }

}
public interface DemoService {
    String sayHello(String name);
}

启动测试。

在服务提供方consul-dev,打个断点,模仿服务未响应。

这时请求服务消费方,发现服务熔断了。

 9.负载均衡

在 Spring Cloud 中,@FeignClient 默认使用 Ribbon 作为客户端负载均衡器,但 Ribbon 的具体负载均衡策略是通过 Ribbon 的配置来实现的,而不是直接在 @FeignClient 注解中定义。不过,可以通过全局配置或者自定义 Ribbon 客户端的方式来改变负载均衡策略。

例如,要更改 Ribbon 的负载均衡策略为轮询(默认也是轮询),可以在配置文件中定义:

ribbon:
  NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RoundRobinRule

 从 Spring Cloud Finchley 版本开始,还可以通过 @Configuration 类来自定义 Ribbon 客户端并设置负载均衡策略:

@Configuration
public class RibbonConfig {

    @Bean
    public IRule ribbonRule() {
        return new RandomRule(); // 使用随机策略
    }
}

不过从 Spring Cloud 2020.0.0(Ilford)版本开始,Ribbon 不再作为默认的负载均衡器,而是推荐使用 Spring Cloud LoadBalancer。在 Spring Cloud LoadBalancer 中,可以通过 LoadBalancerClientConfigurationProperties 设置负载均衡策略,或者自定义 org.springframework.cloud.loadbalancer.core.RoundRobinLoadBalancerRandomLoadBalancer 等实现类来实现不同的策略。

例如,使用 Spring Cloud LoadBalancer 时,若要全局配置为随机策略,可以在配置文件中写入:

spring:
  cloud:
    loadbalancer:
      ribbon:
        enabled: true # 启用 Ribbon 作为底层负载均衡器
      default-load-balancer:
        rule: random # 设置默认负载均衡规则为随机

最后记录一下consul配置相关:

consul下文件相关:

/etc/consul.d/consul.env: 这个文件通常用于设置 Consul 运行时的环境变量。环境变量可以影响 Consul 的行为,例如设置日志级别、数据目录路径等。在这个文件中,你可以配置一些 Consul 运行时所需的环境变量。

/etc/consul.d/consul.hcl: 这是 Consul 的主要配置文件。在这个文件中,你可以配置 Consul 的各种选项,包括集群配置、数据中心、节点名称、绑定地址、广告地址、加入集群的地址、监听端口、日志设置等。通过编辑这个文件,你可以定制 Consul 的行为和功能。

/usr/bin/consul: 这是 Consul 的可执行文件。通过执行这个文件,你可以启动 Consul Agent,并根据配置文件中的设置来运行 Consul。

/usr/lib/systemd/system/consul.service: 这是 Consul 的 Systemd 服务单元文件。它定义了 Consul 作为 Systemd 服务的配置,包括服务的启动方式、依赖关系等。通过 Systemd,你可以使用 systemctl 命令来管理 Consul 服务的启动、停止、重启等操作。

# Consul 配置文件

# 数据中心设置
datacenter = "dc1"

# 节点名称设置(注意:不可重名)
node_name = "consul-36"

# 数据目录设置
data_dir = "/opt/consul"

# 日志级别设置(可选值:TRACE, DEBUG, INFO, WARN, ERR)
log_level = "ERR"

# 绑定地址设置(监听所有 IPv6 地址和所有 IPv4 地址)
bind_addr = "[::]"
bind_addr = "0.0.0.0"

# 广播自己地址给集群访问(用于集群内部通信)
advertise_addr = "192.168.0.36"

# 加入集群的地址列表(需要提供至少一个已知的集群节点地址,:8301默认端口可省略)
retry_join = ["192.168.0.122:8301", "192.168.0.123", "192.168.0.124"]
# 用于指定 Consul Agent 在启动时尝试通过加入集群节点。
start_join = ["192.168.0.122", "192.168.0.123", "192.168.0.124"]

# 服务节点设置(是否为服务器节点)
server = true
# 这会告诉Consul在引导期间等待2个服务器节点就绪,然后再引导整个集群。
bootstrap_expect = 2

# 加密设置(consul keygen 生成的用于集群网络通信的加密)
encrypt = ""

# 客户端地址设置(用于监听客户端请求的地址)
client_addr = "0.0.0.0"

# UI 配置(用于启用内置的 Web UI)
ui_config {
  enabled = true
  content_path = "/ui/" #可自定义路径
}

# 默认端口设置
ports {
  # HTTP API 端口(默认值:8500)与 Consul 进行交互,包括服务注册、UI、健康检查等
  http = 8500
  # DNS 端口(默认值:8600)用于提供 DNS 查询服务,允许客户端通过 DNS 协议来查询服务实例的地址
  dns = 8600
  # Serf LAN 端口(默认值:8301)局域网内进行集群节点间的通信
  serf_lan = 8301
  # Serf WAN 端口(默认值:8302) 广域网(WAN)内进行集群节点间的通信,用于跨数据中心的通信
  serf_wan = 8302
  # 服务器 RPC 端口(默认值:8300)服务器节点之间进行 RPC 通信
  server = 8300
}

# 启动
consul agent -config-file=/etc/consul.d

以下是一些常用的 Consul 集群管理命令:

启动 Consul Agent:consul agent -config-file=<config_file>
这个命令用于启动 Consul Agent,并指定配置文件。

加入集群:consul join <address>
这个命令用于将当前节点加入到 Consul 集群中,<address> 是一个已存在的集群节点的地址。

离开集群:consul leave
这个命令用于将当前节点从 Consul 集群中移除。

查看集群节点:consul members
这个命令用于查看当前 Consul 集群中的成员节点列表。

查看 Leader:consul operator raft list-peers
这个命令用于列出当前的 Consul 集群中的领导者节点。

手动推选 Leader:consul operator raft promote <node_id>

这个命令用于手动推选指定节点为 Consul 集群的领导者。

重启集群节点:consul reload
这个命令用于重新加载 Consul 配置文件并重启 Consul Agent。

查看服务列表:consul catalog services
这个命令用于列出所有在 Consul 中注册的服务。

注册服务:consul services register <service.json>
这个命令用于注册一个新的服务到 Consul 中,<service.json> 是包含服务定义的 JSON 文件。

移除服务:consul services deregister <service_id>
这个命令用于从 Consul 中移除一个已注册的服务,<service_id> 是服务的唯一标识符。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43970625/article/details/137873891

智能推荐

class和struct的区别-程序员宅基地

文章浏览阅读101次。4.class可以有⽆参的构造函数,struct不可以,必须是有参的构造函数,⽽且在有参的构造函数必须初始。2.Struct适⽤于作为经常使⽤的⼀些数据组合成的新类型,表示诸如点、矩形等主要⽤来存储数据的轻量。1.Class⽐较适合⼤的和复杂的数据,表现抽象和多级别的对象层次时。2.class允许继承、被继承,struct不允许,只能继承接⼝。3.Struct有性能优势,Class有⾯向对象的扩展优势。3.class可以初始化变量,struct不可以。1.class是引⽤类型,struct是值类型。

android使用json后闪退,应用闪退问题:从json信息的解析开始就会闪退-程序员宅基地

文章浏览阅读586次。想实现的功能是点击顶部按钮之后按关键字进行搜索,已经可以从服务器收到反馈的json信息,但从json信息的解析开始就会闪退,加载listview也不知道行不行public abstract class loadlistview{public ListView plv;public String js;public int listlength;public int listvisit;public..._rton转json为什么会闪退

如何使用wordnet词典,得到英文句子的同义句_get_synonyms wordnet-程序员宅基地

文章浏览阅读219次。如何使用wordnet词典,得到英文句子的同义句_get_synonyms wordnet

系统项目报表导出功能开发_积木报表 多线程-程序员宅基地

文章浏览阅读521次。系统项目报表导出 导出任务队列表 + 定时扫描 + 多线程_积木报表 多线程

ajax 如何从服务器上获取数据?_ajax 获取http数据-程序员宅基地

文章浏览阅读1.1k次,点赞9次,收藏9次。使用AJAX技术的好处之一是它能够提供更好的用户体验,因为它允许在不重新加载整个页面的情况下更新网页的某一部分。另外,AJAX还使得开发人员能够创建更复杂、更动态的Web应用程序,因为它们可以在后台与服务器进行通信,而不需要打断用户的浏览体验。在Web开发中,AJAX(Asynchronous JavaScript and XML)是一种常用的技术,用于在不重新加载整个页面的情况下,从服务器获取数据并更新网页的某一部分。使用AJAX,你可以创建异步请求,从而提供更快的响应和更好的用户体验。_ajax 获取http数据

Linux图形终端与字符终端-程序员宅基地

文章浏览阅读2.8k次。登录退出、修改密码、关机重启_字符终端

随便推点

Python与Arduino绘制超声波雷达扫描_超声波扫描建模 python库-程序员宅基地

文章浏览阅读3.8k次,点赞3次,收藏51次。前段时间看到一位发烧友制作的超声波雷达扫描神器,用到了Arduino和Processing,可惜啊,我不会Processing更看不懂人家的程序,咋办呢?嘿嘿,所以我就换了个思路解决,因为我会一点Python啊,那就动手吧!在做这个案例之前先要搞明白一个问题:怎么将Arduino通过超声波检测到的距离反馈到Python端?这个嘛,我首先想到了串行通信接口。没错!就是串口。只要Arduino将数据发送给COM口,然后Python能从COM口读取到这个数据就可以啦!我先写了一个测试程序试了一下,OK!搞定_超声波扫描建模 python库

凯撒加密方法介绍及实例说明-程序员宅基地

文章浏览阅读4.2k次。端—端加密指信息由发送端自动加密,并且由TCP/IP进行数据包封装,然后作为不可阅读和不可识别的数据穿过互联网,当这些信息到达目的地,将被自动重组、解密,而成为可读的数据。不可逆加密算法的特征是加密过程中不需要使用密钥,输入明文后由系统直接经过加密算法处理成密文,这种加密后的数据是无法被解密的,只有重新输入明文,并再次经过同样不可逆的加密算法处理,得到相同的加密密文并被系统重新识别后,才能真正解密。2.使用时,加密者查找明文字母表中需要加密的消息中的每一个字母所在位置,并且写下密文字母表中对应的字母。_凯撒加密

工控协议--cip--协议解析基本记录_cip协议embedded_service_error-程序员宅基地

文章浏览阅读5.7k次。CIP报文解析常用到的几个字段:普通类型服务类型:[0x00], CIP对象:[0x02 Message Router], ioi segments:[XX]PCCC(带cmd和func)服务类型:[0x00], CIP对象:[0x02 Message Router], cmd:[0x101], fnc:[0x101]..._cip协议embedded_service_error

如何在vs2019及以后版本(如vs2022)上添加 添加ActiveX控件中的MFC类_vs添加mfc库-程序员宅基地

文章浏览阅读2.4k次,点赞9次,收藏13次。有时候我们在MFC项目开发过程中,需要用到一些微软已经提供的功能,如VC++使用EXCEL功能,这时候我们就能直接通过VS2019到如EXCEL.EXE方式,生成对应的OLE头文件,然后直接使用功能,那么,我们上篇文章中介绍了vs2017及以前的版本如何来添加。但由于微软某些方面考虑,这种方式已被放弃。从上图中可以看出,这一功能,在从vs2017版本15.9开始,后续版本已经删除了此功能。那么我们如果仍需要此功能,我们如何在新版本中添加呢。_vs添加mfc库

frame_size (1536) was not respected for a non-last frame_frame_size (1024) was not respected for a non-last-程序员宅基地

文章浏览阅读785次。用ac3编码,执行编码函数时报错入如下:[ac3 @ 0x7fed7800f200] frame_size (1536) was not respected for anon-last frame (avcodec_encode_audio2)用ac3编码时每次送入编码器的音频采样数应该是1536个采样,不然就会报上述错误。这个数字并非刻意固定,而是跟ac3内部的编码算法原理相关。全网找不到,国内音视频之路还有很长的路,音视频人一起加油吧~......_frame_size (1024) was not respected for a non-last frame

Android移动应用开发入门_在安卓移动应用开发中要在活动类文件中声迷你一个复选框变量-程序员宅基地

文章浏览阅读230次,点赞2次,收藏2次。创建Android应用程序一个项目里面可以有很多模块,而每一个模块就对应了一个应用程序。项目结构介绍_在安卓移动应用开发中要在活动类文件中声迷你一个复选框变量

推荐文章

热门文章

相关标签