esanchezros / quickfixj-spring-boot-starter

Spring Boot Starter for QuickFIX/J
Apache License 2.0
125 stars 57 forks source link

use @EnableQuickFixJClient HTTP interface unreachable #86

Closed maolinHu closed 2 years ago

maolinHu commented 2 years ago

SpringBoot with QuickFIX/J Client, After the Application is started, all web interfaces cannot be accessed, include http://localhost:8080/actuator/quickfixjclient

esanchezros commented 2 years ago

Hi @maolinHu

Could you try adding this to your application.yml:

management:
  endpoints:
    enabled-by-default: true
    web:
      exposure:
        include: "*"
  endpoint:
    quickfixjclient:
      enabled: true
esanchezros commented 2 years ago

Also, make sure you include the spring-boot-starter-web dependency in your pom:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
maolinHu commented 2 years ago

Yes, I have, but it still doesn't work

esanchezros commented 2 years ago

Have a look at this example https://github.com/esanchezros/quickfixj-spring-boot-starter-examples/tree/master/simple-client from the examples repo. It's a web app with quickfixj enabled. If the problem persists could you send your pom and Spring Boot config to check?

maolinHu commented 2 years ago

this is my application.yaml

server:
  port: 8081

quickfixj:
  client:
    config: classpath:quickfixj-client.cfg
    auto-startup: false

management:
  endpoint:
    quickfixjclient:
      enabled: true
  endpoints:
    web:
      exposure:
        include: "*"
maolinHu commented 2 years ago

this is my pom.xml

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>io.allune</groupId>
            <artifactId>quickfixj-spring-boot-starter</artifactId>
            <version>2.11.0</version>
        </dependency>

        <dependency>
            <groupId>io.allune</groupId>
            <artifactId>quickfixj-spring-boot-actuator</artifactId>
            <version>2.11.0</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
maolinHu commented 2 years ago

but I use @EventListener don't implements Application interface

esanchezros commented 2 years ago

What happens if you remove the @EnableQuickFixJClient annotation and QuickFixJ Spring Boot starter dependencies? Does the application start?

maolinHu commented 2 years ago

If remove, all interfaces can be accessed normally

maolinHu commented 2 years ago

this is my Controller, when I add @EnableQuickFixJClient annotation, this interface http://localhost:8081/fix/test will unreachable ` @Slf4j @RequestMapping("/fix") @RestController public class TestController {

@GetMapping("/test")
public String test() throws Exception {
    log.info("test");
    return "success";
}

} `

esanchezros commented 2 years ago

I added your REST controller to https://github.com/esanchezros/quickfixj-spring-boot-starter-examples/tree/master/simple-client and I can access http://localhost:8081/fix/test and http://localhost:8081/actuator/quickfixjclient fine

maolinHu commented 2 years ago

If I set SocketUseSSL=Y, it's ok, But if I set SocketUseSSL=N, all interface will unreachable. this is my client start log 2022-06-13 11:21:43.183 INFO 20168 --- [pool-1-thread-1] i.a.q.s.b.s.connection.ConnectorManager : start: Starting ConnectorManager 2022-06-13 11:21:43.235 INFO 20168 --- [pool-1-thread-1] quickfix.DefaultSessionSchedule : [FIXT.1.1:UAT-ATLTD-MKT1->UAT-ICBCS-ATLTD-MKT1:Rates] daily, 16:00:00-UTC - 16:00:00-UTC (daily, 00:00:00-CST - 00:00:00-CST) 2022-06-13 11:21:43.267 INFO 20168 --- [pool-1-thread-1] c.g.q.service.ClientApplicationAdapter : onCreate: SessionId=FIXT.1.1:UAT-ATLTD-MKT1->UAT-ICBCS-ATLTD-MKT1:Rates 2022-06-13 11:21:43.271 INFO 20168 --- [pool-1-thread-1] quickfix.mina.NetworkingOptions : Socket option: SocketTcpNoDelay=true 2022-06-13 11:21:43.272 INFO 20168 --- [pool-1-thread-1] quickfix.mina.NetworkingOptions : Socket option: SocketSynchronousWrites=false 2022-06-13 11:21:43.272 INFO 20168 --- [pool-1-thread-1] quickfix.mina.NetworkingOptions : Socket option: SocketSynchronousWriteTimeout=30000 2022-06-13 11:21:43.296 INFO 20168 --- [pool-1-thread-1] quickfix.ThreadedSocketInitiator : SessionTimer started 2022-06-13 11:21:43.623 INFO 20168 --- [)-172.254.0.124] quickfix.DefaultSessionSchedule : [FIXT.1.1:UAT-ATLTD-MKT1->UAT-ICBCS-ATLTD-MKT1:Rates] daily, 16:00:00-UTC - 16:00:00-UTC (daily, 00:00:00-CST - 00:00:00-CST) 2022-06-13 11:21:43.626 INFO 20168 --- [)-172.254.0.124] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2022-06-13 11:21:43.626 INFO 20168 --- [)-172.254.0.124] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2022-06-13 11:21:43.633 INFO 20168 --- [)-172.254.0.124] o.s.web.servlet.DispatcherServlet : Completed initialization in 7 ms 2022-06-13 11:21:44.316 INFO 20168 --- [ QFJ Timer] c.g.q.service.ClientApplicationAdapter : toAdmin: Message=8=FIXT.1.19=10235=A34=149=UAT-ATLTD-MKT152=20220613-03:21:44.31556=UAT-ICBCS-ATLTD-MKT198=0108=30141=N1137=810=023, SessionId=FIXT.1.1:UAT-ATLTD-MKT1->UAT-ICBCS-ATLTD-MKT1:Rates Disconnected from the target VM, address: '127.0.0.1:7058', transport: 'socket'

esanchezros commented 2 years ago

HTTP endpoints are accessible, we have multiple services using the Spring Boot starter using HTTP on a daily basis. Do you mean you can't access the FIX endpoints? I noticed you have auto-startup: false. Unless you're starting the connector manually on start up, you will need to set auto-startup: true in order to start the connection with the acceptor

maolinHu commented 2 years ago

Set auto-startup: false, because I suspect that the main thread is blocked by the client when the main thread is started, So I call clientConnectorManager.start() on another thread after the service is started. I just found that this happens when the client sends a message to the server, but does not receive any response. then all http interface cannot be accessed. send message is this (toAdmin: Message=8=FIXT.1.19=10235=A34=149=UAT-ATLTD-MKT152=20220613-07:26:29.29956=UAT-ICBCS-ATLTD-MKT198=0108=30141=N1137=810=046, SessionId=FIXT.1.1:UAT-ATLTD-MKT1->UAT-ICBCS-ATLTD-MKT1:Rates) this is my test repositories https://github.com/maolinHu/quickfix.git, https://github.com/maolinHu/quickfixserver.git. If you can, you can try to reproduce it. This is particularly likely to happen when the client and server are stopped and then started again. Thank you very much.

esanchezros commented 2 years ago

I have checked out the projects and they work fine, I can access the REST endpoints. Are you running the server at the same time?

With regards to your comment about the REST endpoint being inaccessible when stopping and starting the client, I created a couple of endpoints in TestController to start and stop the connector, and I still could access the REST endpoints:

    @Autowired
    private ConnectorManager clientConnectorManager;

    @GetMapping("/start")
    public String start() {
        log.info("start QuickFixJClient");
        Executors.newSingleThreadExecutor().execute(() -> clientConnectorManager.start());

        return "STARTED";
    }

    @GetMapping("/stop")
    public String stop() {
        log.info("stop QuickFixJClient");
        clientConnectorManager.stop();

        return "STOPPED";
    }

The ConnectorManager is a SmartLifecycle bean that gets started as part of Spring's context initialization. You control this by setting auto-start: true in the configuration. ConnectorManager calls Connector#start, which is not a blocking operation.

If you want the ConnectorManager starting up at a later phase (like last), you can control that by setting phase to a large integer (by default is set to Integer.MAX_VALUE).

maolinHu commented 2 years ago

Thank you very much for your patience. I don't have similar problems now. Thank you again.

esanchezros commented 2 years ago

No worries. Thanks for using the library