RabbitMQ by Example: Multiple Threads, Channels and Queues

I just read&nbsp;<a href="http://www.rabbitmq.com/api-guide.html" target="_blank">RabbitMQ's Java API docs</a>, and found it very informative and straight-forward. The example for how to set up a simple&nbsp;<code>Channel</code>&nbsp;for publishing/consuming is very easy to follow and understand. But it's a very simple/basic example, and it left me with an important question:&nbsp;<strong>How can I set up 1+&nbsp;</strong><code><strong>Channels</strong></code><strong>&nbsp;to publish/consume to and from multiple queues?</strong>

I just read RabbitMQ's Java API docs, and found it very informative and straight-forward. The example for how to set up a simple Channel for publishing/consuming is very easy to follow and understand. But it's a very simple/basic example, and it left me with an important question: How can I set up 1+ Channels to publish/consume to and from multiple queues?

Let's say I have a RabbitMQ server with 3 queues on it: loggingsecurity_events and customer_orders. So we'd either need a single Channel to have the ability to publish/consume to all 3 queues, or more likely, have 3 separate Channels, each dedicated to a single queue.

On top of this, RabbitMQ's best practices dictate that we set up 1 Channel per consumer thread. For this example, let's say security_events is fine with only 1 consumer thread, but logging and customer_order both need 5 threads to handle the volume. So, if I understand correctly, does that mean we need:

  • Channel and 1 consumer thread for publishing/consuming to and from security_events; and
  • Channels and 5 consumer threads for publishing/consuming to and from logging; and
  • Channels and 5 consumer threads for publishing/consuming to and from customer_orders?

If my understanding is misguided here, please begin by correcting me. Either way, could some battle-weary RabbitMQ veteran help me "connect the dots" with a decent code example for setting up publishers/consumers that meet my requirements here? Thanks in advance!

How to disable cache in apollo-link or apollo-client?

I'm using&nbsp;<em>apollo-client</em>,&nbsp;<em>apollo-link</em>&nbsp;and&nbsp;<em>react-apollo</em>, I want to fully disable cache, but don't know how to do it.

I'm using apollo-clientapollo-link and react-apollo, I want to fully disable cache, but don't know how to do it.

I read the source of apollo-cache-inmemory, it has a config argument in its constructor, but I can't build a dummy storeFactory to make it works.

How to disable cache in apollo-link or apollo-client?

I'm using&nbsp;<em>apollo-client</em>,&nbsp;<em>apollo-link</em>&nbsp;and&nbsp;<em>react-apollo</em>, I want to fully disable cache, but don't know how to do it.

I'm using apollo-clientapollo-link and react-apollo, I want to fully disable cache, but don't know how to do it.

I read the source of apollo-cache-inmemory, it has a config argument in its constructor, but I can't build a dummy storeFactory to make it works.

Apollo link state setup?

Im trying to set up Apollo link state following the docs:&nbsp;<a href="https://github.com/apollographql/apollo-link-state" target="_blank">https://github.com/apollographql/apollo-link-state</a>

Im trying to set up Apollo link state following the docs: https://github.com/apollographql/apollo-link-state

    import React from 'react';
    import ReactDOM from 'react-dom';
    import { HttpLink, InMemoryCache, ApolloClient } from 'apollo-client-preset';
    import { WebSocketLink } from 'apollo-link-ws';
    import { ApolloLink, split } from 'apollo-link';
    import { getMainDefinition } from 'apollo-utilities';
    import { AUTH_TOKEN } from './constant';
    import RootContainer from './components/RootContainer';
    import { ApolloProvider } from 'react-apollo';
const httpLink = new HttpLink({ uri: 'http://localhost:4000' });

const middlewareLink = new ApolloLink((operation, forward) =&gt; {

ation token from local storage if it exists
const tokenValue = localStorage.getItem(AUTH_TOKEN);
operation.setContext({
headers: {
Authorization: tokenValue ? Bearer ${tokenValue} : '',
},
});
return forward(operation);
});

const httpLinkAuth = middlewareLink.concat(httpLink);

const wsLink = new WebSocketLink({
  uri: `ws://localhost:4000`,
  options: {
    reconnect: true,
    connectionParams: {
      Authorization: `Bearer ${localStorage.getItem(AUTH_TOKEN)}`,
    },
  },
});

const link = split(
  ({ query }) =&gt; {
    const { kind, operation } = getMainDefinition(query);
    return kind === 'OperationDefinition' &amp;&amp; operation === 'subscription';
  },
  wsLink,
  httpLinkAuth,
);

const client = new ApolloClient({
  clientState: {
    defaults: {
      isConnected: true,
    },
    resolvers: {
      Mutation: {
        updateNetworkStatus: (_, { isConnected }, { cache }) =&gt; {
          cache.writeData({ data: { isConnected } });
          return null;
        },
      },
    },
  },

  link: ApolloLink.from([link]),

  cache: new InMemoryCache(),

  connectToDevTools: true,
});

const token = localStorage.getItem(AUTH_TOKEN);

ReactDOM.render(
  &lt;ApolloProvider client={client}&gt;
    &lt;RootContainer token={token} /&gt;
  &lt;/ApolloProvider&gt;,
  document.getElementById('root'),
);

When I try a query:

{
networkStatus @client {
isConnected
}
}

I get this error

    {
"errors": [
{
"message": "Response not successful: Received status code 400",
"locations": [
"Error: Response not successful: Received status code 400\n at throwServerError (http://localhost:3000/static/js/bundle.js:5296:17)\n at http://localhost:3000/static/js/bundle.js:5321:13"
]
}
]
}

UPDATED CODE: I'm no longer getting errors but the query returned is always an empty object.

import React from 'react';
import ReactDOM from 'react-dom';
import { HttpLink, InMemoryCache, ApolloClient } from 'apollo-client-preset';
import { WebSocketLink } from 'apollo-link-ws';
import { ApolloLink, split } from 'apollo-link';
import { getMainDefinition } from 'apollo-utilities';
import { AUTH_TOKEN } from './constant';
import RootContainer from './components/RootContainer';
import { ApolloProvider } from 'react-apollo';
import { withClientState } from 'apollo-link-state';
import { gql } from 'apollo-boost';

const httpLink = new HttpLink({ uri: 'http://localhost:4000' });

const middlewareLink = new ApolloLink((operation, forward) => {
// get the authentication token from local storage if it exists
const tokenValue = localStorage.getItem(AUTH_TOKEN);
// return the headers to the context so httpLink can read them
operation.setContext({
headers: {
Authorization: tokenValue ? Bearer ${tokenValue} : '',
},
});
return forward(operation);
});

// authenticated httplink
const httpLinkAuth = middlewareLink.concat(httpLink);

const wsLink = new WebSocketLink({
uri: ws://localhost:4000,
options: {
reconnect: true,
connectionParams: {
Authorization: Bearer ${localStorage.getItem(AUTH_TOKEN)},
},
},
});

const link = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLink,
httpLinkAuth,
);

const cache = new InMemoryCache();

const stateLink = withClientState({
cache,
resolvers: {
Query: {
networkStatus: (, args, { cache }) => {
return cache.readQuery({
query: gql query { networkStatus @client { isConnected } } ,
});
},
},
Mutation: {
updateNetworkStatus: (
, { isConnected }, { cache }) => {
const data = {
networkStatus: {
__typename: 'NetworkStatus',
isConnected,
},
};
cache.writeData({ data });
return null;
},
},
},
defaults: {
networkStatus: {
__typename: 'NetworkStatus',
isConnected: true,
},
},
});

// apollo client setup
const client = new ApolloClient({
link: ApolloLink.from([stateLink, link]),
cache,
connectToDevTools: true,
});

const token = localStorage.getItem(AUTH_TOKEN);

ReactDOM.render(
<ApolloProvider client={client}>
<RootContainer token={token} />
</ApolloProvider>,
document.getElementById('root'),
);

If I remove defaults then the query isn't recognised. So I think im either writing or reading from the store incorrectly.