【问题标题】:Transfering image/jpeg between two nodes of hazelcast在 hazelcast 的两个节点之间传输图像/jpeg
【发布时间】:2021-09-04 03:37:04
【问题描述】:

我在 hazelcast 中有两个节点,例如客户端和服务器。这两个应用程序都是在 spring-boot 上编写的。服务器去外部 api 获取一些图像并返回 InputStream 的想法(在从 CloseableHttpResponse 对象中提取 httpResponse.getEntity().getContent() 之后)。然后客户端应该通过 Hazelcast(可调用对象负责此)获取此图像,并将字节 [] 返回给浏览器,以便浏览器显示图像。

这是两个节点之间的可调用对象:

public class ExecuteCallable implements Callable<IputStream>, Serializable {

private static final long serialVersionUID = 5745765873707162281L;

private SomeObject someObject;

public ExecuteCallable(SomeObject someObject) {
    this.someObject= someObject;
}

public IputStream call() {
    try {
        
       DistributedExecutor distributedExecutor = (DistributedExecutor) ApplicationContextProvider
                .getApplicationContext().getBean(DISTRIBUTED_EXECUTOR_BEAN_NAME);

         return distributedExecutor.executeGetImage(someObject);
    } finally {
      //some tasks
    }
}

}

当服务器返回到客户端 InputStream 对象时,我得到这个错误:

Caused by: com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable serializer for class org.apache.http.conn.EofSensorInputStream

我尝试返回准备好的 byte[] 对象,如 IOUtils.toByteArray(inputstream),但也出现错误。

问题是否有可能在两个 hazelcast 节点之间传输一些 ipnutstream 或其字节表示?

【问题讨论】:

    标签: spring-boot inputstream hazelcast hazelcast-imap


    【解决方案1】:

    我通过在 try 资源块中转换输入流而不将输入流返回到外部方法来解决它。否则流以某种方式被异常关闭:

    Caused by: javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
    

    所以我就是这样做的:

        public byte[] doService(String url, SomeObject someObject )
            throws Exception {
    
        HttpUriRequest httpRequest = resolveRequest(url, HttpRequestType.GET, someObject);
    
        LOGGER.info("Generated following URL for request {}", httpRequest.getURI().getSchemeSpecificPart());
        try (CloseableHttpResponse httpResponse = httpTransport
                .sendAndReceive(httpRequest)) {
            int httpStatus = httpResponse.getStatusLine().getStatusCode();
            LOGGER.info("responded with HTTP {}", httpStatus);
    
            if (httpStatus != 0 ) {
                byte[] byteArray = IOUtils.toByteArray(httpResponse.getEntity().getContent());
                return byteArray;
            } else {
               //some tasks
        }
    }
    

    然后我只返回 byte[] 对象,我的数组通过 hazelcast 和 callable(但为 byte[] 定义)返回到我的 spring-boot WEB Rest api,然后它作为图像显示返回到浏览器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-10
      • 2019-09-15
      • 1970-01-01
      • 2017-12-25
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      相关资源
      最近更新 更多