如何编写基本的自定义路由器?

时间:2018-06-18 09:55:22

标签: spring-integration

我在一个非常天真的自定义路由器上获得1> MOC ..\include\ccFE\AppService.h 1> The system cannot find the path specified. 1> MOC ..\include\ccFE\PluginWidgetWebPage.h 1> The system cannot find the path specified. 1> MOC ..\include\ccFE\URLHandler.h 1> The system cannot find the path specified. 1> MOC ..\include\ccFE\YenkaWebPage.h 1> The system cannot find the path specified. 1> MOC ..\include\ccFE\YenkaWidget.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\AutoLayoutBaseSet.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\ComputedPropertyCallback.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\ContentsTreeStore.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\DocumentService.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\EventRegistry.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\Formatter.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\LiveQuerySet.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\NodeFilter.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\OutputTransform.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\OutputTransformManager.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\PartAssociationHelper.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\PartsTreeStore.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\PhononMediaPlayer.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\PixelDistanceConverter.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\ReplacementSet.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\SetValueCommand.h 1> The system cannot find the path specified. 1> MOC ..\include\ccModel\TreeStore.h 1> The system cannot find the path specified. 1> MOC ..\include\cc\AccurateTimer.h 1> The system cannot find the path specified. 1> MOC ..\include\cc\FeatureService.h 1> The system cannot find the path specified. 1> MOC ..\include\cc\HttpFileHandler.h 1> The system cannot find the path specified. 1> MOC ..\include\cc\JavaScriptBridge.h 1> The system cannot find the path specified. 1> MOC ..\include\cc\SettingsService.h 1> The system cannot find the path specified. 1> MOC ..\include\cc\Signaller.h 1> The system cannot find the path specified. 1> MOC ..\include\cc\WeakPointer.h 1> The system cannot find the path specified. 1> MOC collision\CollisionSpaceImpl.h 1> The system cannot find the path specified. 1> MOC commandManager\commandManager.h 1> The system cannot find the path specified. 1> MOC licence\LicenceDownloader.h 1> The system cannot find the path specified. 1> MOC licence\licenceService.h 1> The system cannot find the path specified. 1> MOC model\action_impl.h 1> The system cannot find the path specified. 1> MOC model\borderLayout.h 1> The system cannot find the path specified. 1> MOC model\camera\cameraAnimations\CameraAnimation.h 1> The system cannot find the path specified. 1> MOC model\canRotate3dCallback.h 1> The system cannot find the path specified. 1> MOC model\control_impl.h 1> The system cannot find the path specified. 1> MOC model\document_impl.h 1> The system cannot find the path specified. 1> MOC model\engineRegistry.h 1> The system cannot find the path specified. 1> MOC model\junction_impl.h 1> The system cannot find the path specified. 1> MOC model\linkedProperties.h 1> The system cannot find the path specified. 1> MOC model\link_impl.h 1> The system cannot find the path specified. 1> MOC model\LiveNodeWatcher.h 1> The system cannot find the path specified. 1> MOC model\LivePropertyWatcher.h 1> The system cannot find the path specified. 1> MOC model\Marquee.h 1> The system cannot find the path specified. 1> MOC model\model_impl.h 1> The system cannot find the path specified. 1> MOC model\node_impl.h 1> The system cannot find the path specified. 1> MOC model\pad_impl.h 1> The system cannot find the path specified. 1> MOC model\PartLockingHandler.h 1> The system cannot find the path specified. 1> MOC model\part_impl.h 1> The system cannot find the path specified. 1> MOC model\popup_impl.h 1> The system cannot find the path specified. 1> MOC model\propertyScaleCallback.h 1> The system cannot find the path specified. 1> MOC model\property_impl.h 1> The system cannot find the path specified. 1> MOC model\reflection_impl.h 1> The system cannot find the path specified. 1> MOC model\scene_impl.h 1> The system cannot find the path specified. 1> MOC model\spaceActionProcessor.h 1> The system cannot find the path specified. 1> MOC model\spaceOrient3Callback.h 1> The system cannot find the path specified. 1> MOC model\spacePos3Callback.h 1> The system cannot find the path specified. 1> MOC model\spacePosOrientCallback.h 1> The system cannot find the path specified. 1> MOC model\space_impl.h 1> The system cannot find the path specified. 1> MOC model\xyPosCallback.h 1> The system cannot find the path specified. 1> MOC model\xyzPosCallback.h 1> The system cannot find the path specified. 1> MOC package\packageManager.h 1> The system cannot find the path specified. 1> MOC package\SubjectManager.h 1> The system cannot find the path specified. 1> MOC units\numericalFormatter_impl.h 1> The system cannot find the path specified. 1> MOC util\AuthenticationDialog.h 1> The system cannot find the path specified. 1> MOC util\characterMapDialog.h 1> The system cannot find the path specified. 1> MOC util\HttpFileDownloader.h 1> The system cannot find the path specified. 1> MOC util\LocaleService.h 1> The system cannot find the path specified. 1> MOC util\NetworkProxy.h 1> The system cannot find the path specified. 1> MOC util\nodePropertyWatcher.h 1> The system cannot find the path specified. 1> MOC util\statGraph.h 1> The system cannot find the path specified. 1> MOC validators\baseValidator.h 1> The system cannot find the path specified. 1> MOC util\crashHandler.cpp 1> The system cannot find the path specified. 1> MOC ccFoundation\FeatureService.cpp 1> The system cannot find the path specified. 1> MOC util\statistic.cpp 1> The system cannot find the path specified. 1> MOC model\transaction.cpp 1> The system cannot find the path specified. 1> C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 3. 1> Done executing task "CustomBuild" -- FAILED. 1>Done building target "CustomBuild" in project "ccCore.vcxproj" -- FAILED. 1> 1>Done building project "ccCore.vcxproj" -- FAILED. 1> 1>Build FAILED. 1> 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): warning MSB8017: A circular dependency has been detected while executing custom build commands for item "_moc\crashHandler.moc". This may cause incremental build to work incorrectly. 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): warning MSB8017: A circular dependency has been detected while executing custom build commands for item "_moc\FeatureService.moc". This may cause incremental build to work incorrectly. 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): warning MSB8017: A circular dependency has been detected while executing custom build commands for item "_moc\statistic.moc". This may cause incremental build to work incorrectly. 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): warning MSB8017: A circular dependency has been detected while executing custom build commands for item "_moc\transaction.moc". This may cause incremental build to work incorrectly. 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 3. 1> 4 Warning(s) 1> 1 Error(s) 1> 1>Time Elapsed 00:00:00.31 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

unsupported return type for router

以下是xml的相关部分:

@Autowired
@Qualifier("fromJsonToJsonChannel")
private MessageChannel fromJsonToJsonChannel;

public AbstractMessageRouter determineTransformation(Message<?> message) {
    return new AbstractMessageRouter() {

        @Override
        protected Collection<MessageChannel> determineTargetChannels(Message<?> message) {
            return Collections.singletonList(fromJsonToJsonChannel);
        }

    };
}

这是堆栈跟踪:

<int:router method="determineTransformation" input-channel="inputChannel"
                default-output-channel="fromJsonToJsonChannel">
        <beans:bean class="com.poc.inject.pocinject.CustomRoute"/>
    </int:router>

<int:service-activator ref="jsonDummy" method="json2jsonConvert" input-channel="fromJsonToJsonChannel" output-channel="determineValidationChannel"/>

频道正确自动连线。我做错了什么?

1 个答案:

答案 0 :(得分:1)

我们需要从您的应用中看到更多内容以及您如何使用determineTransformation()

您提到的错误仅在以下情况下发生:

protected Collection<MessageChannel> determineTargetChannels(Message<?> message) {
    Collection<MessageChannel> channels = new ArrayList<MessageChannel>();
    Collection<Object> channelKeys = this.getChannelKeys(message);
    addToCollection(channels, channelKeys, message);
    return channels;
}
AbstractMappingMessageRouter中的

。因此,看起来错误与您的自定义路由器实现无关。

另外,请分享更多关于此事的堆栈跟踪。而且我很好奇是什么让你去实现自定义AbstractMessageRouter。为什么简单的MethodInvokingRouter对你来说还不够?

<强>更新

您的配置错误:

<int:router method="determineTransformation" input-channel="inputChannel"
            default-output-channel="fromJsonToJsonChannel">
    <beans:bean class="com.insightguard.poc.inject.pocinject.CustomRoute"/>
</int:router>

这样您就可以MethodInvokingRouter向每个请求消息上的determineTransformation拨打电话。在查看代码时,您错误地决定为这些消息创建新的AbstractMessageRouter实例。

根据您的要求:

  

我们的想法是让自定义路由器使用该消息,然后使用一些基于数据库的信息(config)来确定将其路由到哪个频道。

拥有一个自定义POJO方法并为每个请求消息返回一组所需的MessageChannel s,但不是新的AbstractMessageRouter实例。粗略地说它必须是这样的:

public MessageChannel determineTransformation(Message<?> message) {
     return fromJsonToJsonChannel;
}

当然,您可以在方法中应用任何自定义逻辑,但重点是您不需要知道有关Router抽象的任何信息。您只需遵循合同并返回MessageChannel或其名称(或其名称或数组)。与AbstractMessageRouter无关!

如果我仍然遗漏了你的意见,请告诉我!