Created
July 28, 2022 00:39
-
-
Save jeremymeng/3ebec5a391c7f901160f6b15f3663c95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 696505db6647dd182eaa4254c035acf518b35e7d Mon Sep 17 00:00:00 2001 | |
From: Jeremy Meng <yumeng@microsoft.com> | |
Date: Wed, 27 Jul 2022 14:33:04 -1000 | |
Subject: [PATCH] override webpack config using `react-app-rewired` | |
--- | |
sb/react-sb/config-overrides.js | 24 +++++++++++ | |
sb/react-sb/package.json | 4 +- | |
sb/react-sb/src/App.tsx | 5 +++ | |
sb/react-sb/src/testSB.ts | 71 +++++++++++++++++++++++++++++++++ | |
4 files changed, 103 insertions(+), 1 deletion(-) | |
create mode 100644 sb/react-sb/config-overrides.js | |
create mode 100644 sb/react-sb/src/testSB.ts | |
diff --git a/sb/react-sb/config-overrides.js b/sb/react-sb/config-overrides.js | |
new file mode 100644 | |
index 0000000..5db1a4f | |
--- /dev/null | |
+++ b/sb/react-sb/config-overrides.js | |
@@ -0,0 +1,24 @@ | |
+const webpack = require("webpack"); | |
+ | |
+module.exports = function override(config) { | |
+ const plugins = config.plugins || []; | |
+ plugins.push( | |
+ new webpack.ProvidePlugin({ | |
+ process: "process/browser", | |
+ }) | |
+ ); | |
+ plugins.push( | |
+ new webpack.ProvidePlugin({ | |
+ Buffer: ["buffer", "Buffer"], | |
+ }) | |
+ ); | |
+ config.plugins = plugins; | |
+ const fallback = config.resolve.fallback || {}; | |
+ Object.assign(fallback, { | |
+ buffer: require.resolve("buffer/"), | |
+ os: require.resolve("os-browserify"), | |
+ path: require.resolve("path-browserify"), | |
+ }); | |
+ config.resolve.fallback = fallback; | |
+ return config; | |
+}; | |
diff --git a/sb/react-sb/package.json b/sb/react-sb/package.json | |
index 2250736..88fa83c 100644 | |
--- a/sb/react-sb/package.json | |
+++ b/sb/react-sb/package.json | |
@@ -19,6 +19,7 @@ | |
}, | |
"scripts": { | |
"start": "react-scripts start", | |
+ "start2": "react-app-rewired start", | |
"build": "react-scripts build", | |
"test": "react-scripts test", | |
"eject": "react-scripts eject" | |
@@ -45,6 +46,7 @@ | |
"buffer": "^6.0.3", | |
"os-browserify": "^0.3.0", | |
"path-browserify": "^1.0.1", | |
- "process": "^0.11.10" | |
+ "process": "^0.11.10", | |
+ "react-app-rewired": "^2.2.1" | |
} | |
} | |
diff --git a/sb/react-sb/src/App.tsx b/sb/react-sb/src/App.tsx | |
index a53698a..404e8ab 100644 | |
--- a/sb/react-sb/src/App.tsx | |
+++ b/sb/react-sb/src/App.tsx | |
@@ -2,6 +2,11 @@ import React from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
+ | |
+import { main as testSB } from "./testSB" | |
+ | |
+testSB().catch(console.error); | |
+ | |
function App() { | |
return ( | |
<div className="App"> | |
diff --git a/sb/react-sb/src/testSB.ts b/sb/react-sb/src/testSB.ts | |
new file mode 100644 | |
index 0000000..38c0886 | |
--- /dev/null | |
+++ b/sb/react-sb/src/testSB.ts | |
@@ -0,0 +1,71 @@ | |
+import { | |
+ delay, | |
+ isServiceBusError, | |
+ ProcessErrorArgs, | |
+ ServiceBusClient, | |
+ ServiceBusReceivedMessage, | |
+} from "@azure/service-bus"; | |
+ | |
+ // Define connection string and related Service Bus entity names here | |
+ const connectionString = "<connection string>"; | |
+ const queueName = "queue1"; | |
+ | |
+export async function main() { | |
+ const sbClient = new ServiceBusClient(connectionString); | |
+ | |
+ // - If receiving from a subscription you can use the createReceiver(topicName, subscriptionName) overload | |
+ // instead. | |
+ // - See session.ts for how to receive using sessions. | |
+ const receiver = sbClient.createReceiver(queueName); | |
+ | |
+ try { | |
+ const subscription = receiver.subscribe({ | |
+ // After executing this callback you provide, the receiver will remove the message from the queue if you | |
+ // have not already settled the message in your callback. | |
+ // You can disable this by passing `false` to the `autoCompleteMessages` option in the `subscribe()` method. | |
+ // If your callback _does_ throw an error before the message is settled, then it will be abandoned. | |
+ processMessage: async (brokeredMessage: ServiceBusReceivedMessage) => { | |
+ console.log(`Received message: ${brokeredMessage.body}`); | |
+ }, | |
+ // This callback will be called for any error that occurs when either in the receiver when receiving the message | |
+ // or when executing your `processMessage` callback or when the receiver automatically completes or abandons the message. | |
+ processError: async (args: ProcessErrorArgs) => { | |
+ console.log(`Error from source ${args.errorSource} occurred: `, args.error); | |
+ | |
+ // the `subscribe() call will not stop trying to receive messages without explicit intervention from you. | |
+ if (isServiceBusError(args.error)) { | |
+ switch (args.error.code) { | |
+ case "MessagingEntityDisabled": | |
+ case "MessagingEntityNotFound": | |
+ case "UnauthorizedAccess": | |
+ // It's possible you have a temporary infrastructure change (for instance, the entity being | |
+ // temporarily disabled). The handler will continue to retry if `close()` is not called on the subscription - it is completely up to you | |
+ // what is considered fatal for your program. | |
+ console.log( | |
+ `An unrecoverable error occurred. Stopping processing. ${args.error.code}`, | |
+ args.error | |
+ ); | |
+ await subscription.close(); | |
+ break; | |
+ case "MessageLockLost": | |
+ console.log(`Message lock lost for message`, args.error); | |
+ break; | |
+ case "ServiceBusy": | |
+ // choosing an arbitrary amount of time to wait. | |
+ await delay(1000); | |
+ break; | |
+ } | |
+ } | |
+ }, | |
+ }); | |
+ | |
+ // Waiting long enough before closing the receiver to receive messages | |
+ console.log(`Receiving messages for 20 seconds before exiting...`); | |
+ await delay(20000); | |
+ | |
+ console.log(`Closing...`); | |
+ await receiver.close(); | |
+ } finally { | |
+ await sbClient.close(); | |
+ } | |
+} | |
\ No newline at end of file | |
-- | |
2.32.0.windows.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment