【问题标题】:Flink Retrofit not Serializable ExceptionFlink Retrofit 不可序列化异常
【发布时间】:2017-05-12 18:40:10
【问题描述】:

我有一个 Flink 作业从 Kafka 队列读取事件,然后在满足某些条件时调用另一个服务。
我想使用 Retrofit2 来调用该服务的 REST 端点,但我得到一个不可序列化的异常。我有几个相互连接的平面地图(串联),然后在最后一个平面地图中调用服务。我得到的例外:

线程“main”中的异常 org.apache.flink.api.common.InvalidProgramException: RichFlatMapFunction 的实现不可序列化。这 对象可能包含或引用不可序列化的字段。
...
引起:java.io.NotSerializableException:retrofit2.Retrofit$1
...

我初始化改造的方式:

RetrofitClient.getClient(BASE_URL).create(NotificationService.class);

还有 NotificationService 接口

public interface NotificationService {

    @PUT("/test")
    Call<String> putNotification(@Body Notification notification);
}

RetrofitClient 类

public class RetrofitClient {

    private static Retrofit retrofit = null;

    public static Retrofit getClient(String baseUrl) {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder().baseUrl(baseUrl).addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }

【问题讨论】:

    标签: retrofit retrofit2 apache-flink flink-streaming


    【解决方案1】:

    将您的通知类代码放入更多详细信息,但看起来这个答案有帮助 java.io.NotSerializableException with "$1" after class

    【讨论】:

    • 但我做到了,它是一个界面。
    • 您添加了 NotificationService 接口,但在这一行看起来像问题 Call putNotification(@Body Notification notification);您在请求通知类的主体中添加,看起来有问题。那么你可以添加通知类源
    • public class Notification 实现 Serializable { private static final long serialVersionUID = 1L;私有字符串 id;私有字符串文本; getter & setter 在这里 }
    • 事实上我用字符串替换了通知并修改了代码,仍然得到相同的异常。
    • 哦,清楚。您尝试序列化改造类。但是第一项 pf 改造类: public final class Retrofit { private final Map> serviceMethodCache = new ConcurrentHashMap(); java.lang.reflect.Method 无法序列化。
    猜你喜欢
    • 1970-01-01
    • 2015-09-27
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多