GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 【小程序】路由规则使用异步时,当前的appId没有传入到子线程,导致wxMaService在子线程中无法取到父线程的appId。 by biubiubiu3971 · Pull Request #2961 · binarywang/WxJava

Conversation

@biubiubiu3971

@biubiubiu3971 biubiubiu3971 commented Mar 23, 2023

Copy link
Copy Markdown

小程序异步执行消息路由时子线程添加appid

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@biubiubiu3971
【小程序】路由规则使用异步时,当前的appId没有传入到子线程,导致wxMaService在子线程中无法取到父线程的appId。
a075c61
@binarywang
binarywang merged commit bae84e1 into binarywang:develop Mar 24, 2023
@FreeOfYou

FreeOfYou commented Apr 29, 2023

Copy link
Copy Markdown

我用反射改成了使用阿里的TTL的线程池了

//初始化为微信的公共包数据
    static {
        //改变threadLocal为ttl的
        setTTlThreadPool();
    }

    @SneakyThrows
    @SuppressWarnings({"rawtypes", "unchecked"})
    private static void setTTlThreadPool() {
        TransmittableThreadLocal<String> ttlThreadLocal = new TransmittableThreadLocal() {
            @Override
            protected String initialValue() {
                return "default";
            }
        };
        Field threadLocal = ReflectionUtils.findField(WxMaConfigHolder.class, "THREAD_LOCAL");
        if (threadLocal != null) {
            ReflectionUtils.makeAccessible(threadLocal);
            Field modifiers = ReflectionUtils.findField(threadLocal.getClass(), StringPool.MODIFIERS);
            if (modifiers != null) {
                ReflectionUtils.makeAccessible(modifiers);
                ReflectionUtils.setField(modifiers, threadLocal, threadLocal.getModifiers() ^ Modifier.FINAL);
            }
            ReflectionUtils.setField(threadLocal, WxMaConfigHolder.class, ttlThreadLocal);
        }
    }
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nadirvishun

nadirvishun commented Apr 30, 2023

Copy link
Copy Markdown

原先没有这个功能的时候是从context上下文中传递过去的,比较麻烦:

    private void route(WxMaMessage message, String appid) {
        //将appid传递到过去,否则如果是异步路由,无法从threadLocal中获取当前appid
        Map<String, Object> context = new HashMap<>();
        context.put(WxampContextConstants.APPID, appid);
        try {
            wxMaMessageRouter.route(message, context);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@biubiubiu3971

biubiubiu3971 commented Apr 30, 2023

Copy link
Copy Markdown
Author

原先没有这个功能的时候是从context上下文中传递过去的,比较麻烦:

    private void route(WxMaMessage message, String appid) {
        //将appid传递到过去,否则如果是异步路由,无法从threadLocal中获取当前appid
        Map<String, Object> context = new HashMap<>();
        context.put(WxampContextConstants.APPID, appid);
        try {
            wxMaMessageRouter.route(message, context);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

是的,在实际业务执行的handler里面如果有对微信请求的话,里面还需要设置一遍,比较麻烦。

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@biubiubiu3971 @FreeOfYou @nadirvishun @binarywang
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.